File indexing completed on 2022-11-29 18:26:11

0001 #include <QApplication>
0002 #include <QWidget>
0003 #include <QEvent>
0004 #include <QCheckBox>
0005 
0006 #include "kprogressdialog.h"
0007 
0008 class MyWidget : public QWidget
0009 {
0010 public:
0011     MyWidget() : QWidget()
0012     {
0013         setFixedSize(200, 80);
0014         Cancelled = new QCheckBox("Cancelled", this);
0015         Progress = new KProgressDialog(this);
0016         startTimer(50);
0017         Progress->setLabelText("label text");
0018         Progress->setAllowCancel(false);
0019         Progress->showCancelButton(true);
0020         Progress->setButtonText("button text");
0021         Progress->setAutoClose(false);
0022         steps = 300;
0023         Progress->progressBar()->setRange(0, steps);
0024 
0025     }
0026 
0027 private:
0028     KProgressDialog *Progress;
0029     QCheckBox *Cancelled;
0030 
0031     int steps;
0032 
0033     void timerEvent(QTimerEvent *) override;
0034 };
0035 
0036 void MyWidget::timerEvent(QTimerEvent *)
0037 {
0038     Progress->progressBar()->setValue(Progress->progressBar()->value() + 1);
0039     Cancelled->setCheckState(Progress->wasCancelled() ? Qt::Checked : Qt::Unchecked);
0040 }
0041 
0042 int main(int argc, char *argv[])
0043 {
0044     QApplication::setApplicationName("test");
0045     QApplication app(argc, argv);
0046     MyWidget w;
0047 
0048     w.show();
0049 
0050     int ret = app.exec();
0051     return ret;
0052 }