Skip to content

Instantly share code, notes, and snippets.

@kangjianbin
Created November 6, 2015 10:55
Show Gist options
  • Save kangjianbin/f412b44aef62a8a35882 to your computer and use it in GitHub Desktop.
Save kangjianbin/f412b44aef62a8a35882 to your computer and use it in GitHub Desktop.
#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