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

帅比萌擦擦* 提交于 2019-12-20 17:38:00

问题


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. So it seems to be possible - how can I access to the progress bar by hand (without Visual Studio)?


回答1:


I think they used Win7 API functions and encapsulated them in their library. You can include by hand those headers and use them too. Here you can find a help topic and demo project: codeproject.com/KB/vista/SevenGoodiesTaskbarStatus.aspx

But its only for win7. Not crossplatform. Good luck

update mar 05, 2014

This question was asked a long time ago and many things have changed since. For those asking themselves the same question today (beginnings of 2014) then my personal answer is that Qt 5 fully supports progress in taskbar and different kind of beautiful extras. See QWinTaskbarProgress (upd nov 28, 2016) for details




回答2:


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 <QWinTaskbarProgress>
    #include <QWinTaskbarButton>
#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


来源:https://stackoverflow.com/questions/4349502/how-to-show-progress-in-windows-7-taskbar-using-qt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!