How to show progress in windows 7 taskbar (using Qt)?

前端 未结 2 706
感动是毒
感动是毒 2021-02-07 07:04

Is there a way to access the windows 7 progress bar with Qt? I\'m currently using Qt 4.7.0 with Qt Creator.

I already found Q7Goodies but unfortunately it is not free. S

2条回答
  •  既然无缘
    2021-02-07 07:19

    You can use the QWinTaskbarProgress class. To use this class, you need to add win32:QT += winextras in your .pro file.

    Here is an example code showing how to show the value of a QProgressBar in the Windows task bar (inspired from this example):

    #ifdef _WIN32    //The _WIN32 macro is automatically generated when compiling for Windows
        #include 
        #include 
    #endif
    QProgressBar *progressBar = new QProgressBar;
    progressBar->show();
    #ifdef _WIN32
        QWinTaskbarButton *windowsTaskbarButton = new QWinTaskbarButton;    //Create the taskbar button which will show the progress
        windowsTaskbarButton->setWindow(progressBar->windowHandle());    //Associate the taskbar button to the progress bar, assuming that the progress bar is its own window
        QWinTaskbarProgress *windowsTaskbarProgress = windowsTaskbarButton->progress();
        windowsTaskbarProgress->show();
        QObject::connect(loadingWindow, &QProgressBar::valueChanged, [windowsTaskbarProgress](int value){
            windowsTaskbarProgress->setValue(value);   //Change the value of the progress in the taskbar when the value of the progress bar changes
        });
    #endif
    

提交回复
热议问题