如何在Windows 7任务栏中显示进度(使用Qt)?

18

有没有一种方式可以使用Qt访问Windows 7的进度条?我目前正在使用带有Qt Creator的Qt 4.7.0。

我已经找到了Q7Goodies,但不幸的是它并非免费。因此似乎有可能,那么我该如何手动访问进度条(而不使用Visual Studio)?


5
ITaskbarList3::SetProgressValue() 是一个Windows API函数,用于在任务栏中显示进度条的当前值。 - Hans Passant
请参阅KDE任务栏进度条,其中一个答案指向一个存储库,该代码支持KDE和Windows任务栏进度指示器。(我实际上已在两个系统上进行了检查,并确认它可以正常工作。) - Ruslan
2个回答

12

我认为他们使用了Win7 API函数并将它们封装在他们的库中。你可以自己手动包含这些头文件并使用它们。在这里,你可以找到一个帮助主题和演示项目:codeproject.com/KB/vista/SevenGoodiesTaskbarStatus.aspx

但这仅适用于Win7。不是跨平台的。祝好运。

更新于2014年3月5日

这个问题很久以前就被提出了,很多事情都发生了变化。对于那些今天(2014年初)也在思考同样问题的人,我的个人答案是Qt 5完全支持任务栏进度和各种美丽的额外功能。详情请看QWinTaskbarProgress更新于2016年11月28日)。


1
非常感谢。我还没有弄清楚如何做到这一点,特别是在使用QtCreater时似乎很难。也许有人能够利用这篇文章:http://www.qtcentre.org/threads/26974-Qt-and-windows-7-new-Api?p=128880#post128880。我认为我必须尝试使用Visual Studio... - Nedec

3
您可以使用QWinTaskbarProgress类。要使用此类,您需要在.pro文件中添加win32:QT += winextras
以下是一个示例代码,展示如何在Windows任务栏中显示QProgressBar的值(启发自此示例):
#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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接