2010-12-03 88 views
16

有没有办法使用Qt访问Windows 7进度条?我目前在Qt Creator中使用Qt 4.7.0。如何在Windows 7任务栏中显示进度(使用Qt)?

我已经找到了Q7Goodies,但不幸的是它不是免费的。所以它似乎是可能的 - 我怎样才能手动访问进度条(没有Visual Studio)?

+5

ITaskbarList3 :: SetProgressValue()。 – 2010-12-03 20:28:07

回答

10

我认为他们使用Win7 API函数并将它们封装在它们的库中。您可以手动添加这些标题并使用它们。在这里你可以找到一个帮助主题和演示项目:codeproject.com/KB/vista/SevenGoodiesTaskbarStatus.aspx

但它只适用于win7。不是跨平台。祝你好运

更新2014年3月5日

这个问题被问了很久以前,因为很多事情都改变了。对于那些今天(2014年初)自问相同的问题,那么我个人的回答是,Qt 5完全支持任务栏中的进度以及不同类型的美丽附加功能。有关详细信息,请参见QWinTaskbarProgressupd nov 28,2016

+1

非常感谢。我还没有想出如何做到这一点,特别是对于QtCreater而言似乎很难。也许有人能够使用该帖子:http://www.qtcentre.org/threads/26974-Qt-and-windows-7-new-Api?p=128880#post128880。我想我必须使用Visual Studio来尝试它... – Nedec 2010-12-08 06:54:46

0

您可以使用QWinTaskbarProgress类。要使用此类,您需要在.pro文件中添加win32:QT += winextras

这里是展示了如何显示在Windows任务栏(inspired from this example)一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 
相关问题