Created
November 6, 2015 10:55
-
-
Save kangjianbin/f412b44aef62a8a35882 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef TDIALOG_HPP | |
#define TDIALOG_HPP | |
#include <QtWidgets> | |
class TDialog: public QDialog { | |
Q_OBJECT | |
public: | |
explicit TDialog(QWidget *parent=0): QDialog(parent) { | |
QVBoxLayout *l = new QVBoxLayout; | |
m_bar = new QProgressBar; | |
l->addWidget(m_bar); | |
setLayout(l); | |
progress = 0; | |
connect(&m_timer, &QTimer::timeout, this, &TDialog::onTimeout); | |
m_timer.setSingleShot(false); | |
m_timer.setInterval(300); | |
} | |
int exec() { | |
m_timer.start(); | |
progress = 0; | |
m_bar->setValue(progress); | |
return QDialog::exec(); | |
} | |
private slots: | |
void onTimeout() { | |
progress += 10; | |
m_bar->setValue(progress); | |
if (progress == 100) { | |
accept(); | |
progress = 0; | |
} | |
} | |
private: | |
QProgressBar *m_bar; | |
QTimer m_timer; | |
unsigned int progress; | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment