天天看點

Qt工作列進度條顯示設定

看了網上各種,整理可用

1.引用頭檔案

#include <QAbstractButton>

#include <QTimer>

#include <QWinTaskbarButton>

#include <QWinTaskBarProgress>

2.聲明槽

private slots:

    void taskProgress();

    void onTimeout();

3.定義變量

private:

    QTimer *timer;

    QWinTaskbarButton *m_qWinTaskbarButton;

    QWinTaskbarProgress *m_qWinTaskbarProgress;

4.初始化等

timer = new QTimer;

    timer->setInterval(100);

    timer->setSingleShot(false);

    m_qWinTaskbarButton = new QWinTaskbarButton(this);

    connect(timer, &QTimer::timeout, this, &test01::onTimeout);

5.函數實作

void test01::taskProgress()

{

    m_qWinTaskbarButton->setWindow(windowHandle());

    m_qWinTaskbarProgress = m_qWinTaskbarButton->progress();

    m_qWinTaskbarProgress->setRange(0, 100);

    timer->start();

}

void test01::onTimeout() 

{

    m_qWinTaskbarProgress->setValue(m_qWinTaskbarProgress->value() + 1);

    m_qWinTaskbarProgress->show();

}

6.界面按鈕設定

Qt工作列進度條顯示設定

繼續閱讀