Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What am I doing wrong with QWinTaskbarProgress?

I followed the examples I found to make use of the QWinTaskbarProgress. I created a standard Qt Widgets Application in Qt Creator (Qt 5.3.1) and my mainwindow.cpp looks 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 task bar icon to be overlaid and showing 50% progress bar after starting the application, but the task bar looks normal, just as if did not code anything. What am I doing wrong?

like image 486
Chris Avatar asked Feb 12 '23 00:02

Chris


1 Answers

In fact, it seems like calling "m_taskbarButton->setWindow(windowHandle());" in QMainWindow constructor doesn't work and QWinTaskbarProgress won't show at all even after calling setVisible(true) or show().

It has to be called once the Window is shown like in :

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

    e->accept();
}
like image 158
Kervala Avatar answered Feb 14 '23 14:02

Kervala