Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QWinTaskbarProgress won't show

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();
like image 306
K-- Avatar asked Jul 19 '14 13:07

K--


3 Answers

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();
}
like image 73
Kervala Avatar answered Oct 22 '22 13:10

Kervala


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.

like image 25
onli Avatar answered Oct 22 '22 12:10

onli


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));
like image 3
lpapp Avatar answered Oct 22 '22 13:10

lpapp