问题
I'm using windows7 and Qt5.3.0 I added below to my MainWindow's constructor but nothing shows on my taskbar. Did I miss something?
QWinTaskbarProgress * pTaskbarProgress = new QWinTaskbarProgress(this);
pTaskbarProgress->setMinimum(0);
pTaskbarProgress->setMaximum(100);
pTaskbarProgress->setValue(50);
pTaskbarProgress->show();
回答1:
See the example in the documentation:
QWinTaskbarButton *button = new QWinTaskbarButton(widget);
button->setWindow(widget->windowHandle());
button->setOverlayIcon(QIcon(":/loading.png"));
QWinTaskbarProgress *progress = button->progress();
progress->setVisible(true);
progress->setValue(50);
Seems to me like you have to set this as part of a QWinTaskbarButton.
回答2:
In fact, it seems like calling
button->setWindow(widget->windowHandle());
in QMainWindow constructor doesn't work and QWinTaskbarProgress won't show at all even after calling setVisible(true)
or show()
.
If created in the QMainWindow constructor it has to be called once the Window is shown like in:
void MainWindow::showEvent(QShowEvent *e)
{
#ifdef Q_OS_WIN32
m_button->setWindow(windowHandle());
#endif
e->accept();
}
回答3:
The history behind this class is that it was part of QWinTaskbarButton
, thus it was inherently tightly coupled with that class. You can see the relevant upstream commit that began the refactoring and hence decoupling:
Refactor QWinTaskbarProgress out of QWinTaskbarButton
You are right that it is not too explicit in QWinTaskbarProgress' documentation, so this could be potentially improved upstream, but the QWinTaskbarButton example as well as the Music Player example shows the point, namely you have to replace this line:
QWinTaskbarProgress * pTaskbarProgress = new QWinTaskbarProgress(this);
with:
QWinTaskbarButton * pTaskbarButton = new QWinTaskbarButton(this);
pTaskbarButton->setWindow(windowHandle());
QWinTaskbarProgress * pTaskbarProgress = pTaskbarButton->progress();
You may wish to set the overlay icon as well for the taskbar button with either a custom image or something like what the Music Player examples does:
pTaskbarButton->setOverlayIcon(style()->standardIcon(QStyle::SP_MediaPlay));
来源:https://stackoverflow.com/questions/24840941/qwintaskbarprogress-wont-show