What am I doing wrong with QWinTaskbarProgress?

I followed the examples I found to use QWinTaskbarProgress. I created a standard Qt Widgets Applicationin Qt Creator(Qt 5.3.1), and mine mainwindow.cpplooks like this:

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    m_taskbarButton = new QWinTaskbarButton(this);
    m_taskbarButton->setWindow(windowHandle());
    m_taskbarButton->setOverlayIcon(style()->standardIcon(QStyle::SP_MediaPlay));

    m_taskbarProgress = m_taskbarButton->progress();
    m_taskbarProgress->setVisible(true);
    m_taskbarProgress->setRange(0, 100);
    m_taskbarProgress->setValue(50);
}

MainWindow::~MainWindow()
{
    delete ui;
}

I expected the taskbar icon to be superimposed and show a progress bar 50%after starting the application, but the taskbar looks fine, as if it hadn't encoded anything. What am I doing wrong?

+4
source share
2 answers

Actually, it seems that "m_taskbarButton-> setWindow (windowHandle ()) is called; in the constructor, QMainWindow does not work, and QWinTaskbarProgress does not appear at all even after calling setVisible (true) or show ().

, :

void MainWindow::showEvent(QShowEvent *e)
{
#ifdef Q_OS_WIN32
    m_taskbarButton->setWindow(windowHandle());
#endif

    e->accept();
}
+6

Qt Documentation. , , . :

singleShot :

:

private slots:    
    void echo();

:

QTimer::singleShot(1000,this,SLOT(echo()));
QTimer::singleShot(10,this,SLOT(echo()));//works too

Slot:

void MainWindow::echo()
{

    QWinTaskbarButton *button = new QWinTaskbarButton(this);
    button->setWindow(windowHandle());
    button->setOverlayIcon(style()->standardIcon(QStyle::SP_MediaPlay));

    QWinTaskbarProgress *progress = button->progress();
    progress->setVisible(true);
    progress->setRange(0, 100);
    progress->setValue(50);
}

!

0

All Articles