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();
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();
}
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.
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With