Created
June 20, 2013 20:27
-
-
Save arajkumar/5826302 to your computer and use it in GitHub Desktop.
This file contains 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
#include <QtWidgets/QApplication> | |
#include <QtWidgets/QWidget> | |
#include <QTimer> | |
#include <QDebug> | |
class MyQWidget: public QWidget, public QTimer | |
{ | |
friend class MyTimer; | |
public: | |
void timerEvent(QTimerEvent*) | |
{ | |
qDebug()<<"timerEvent"; | |
stop(); | |
} | |
void paintEvent(QPaintEvent* e) | |
{ | |
qDebug()<<"paintEvent"; | |
QWidget::paintEvent(e); | |
} | |
void keyPressEvent(QKeyEvent*) | |
{ | |
qDebug()<<"keyPressEvent"; | |
qDebug()<<"timerstart"; | |
start(0); | |
qDebug()<<"update"; | |
update(geometry()); | |
} | |
}; | |
class MyTimer : public QTimer | |
{ | |
MyQWidget* mWidget; | |
public: | |
MyTimer(MyQWidget* w) | |
: mWidget(w) | |
{ | |
} | |
void timerEvent(QTimerEvent*) | |
{ | |
stop(); | |
qDebug()<<"MyTimer::timerEvent"; | |
qDebug()<<"timerstart"; | |
mWidget->start(0); | |
qDebug()<<"update"; | |
mWidget->update(mWidget->geometry()); | |
} | |
}; | |
int main(int argv, char **args) | |
{ | |
QApplication app(argv, args); | |
MyQWidget textEdit; | |
MyTimer timer(&textEdit); | |
timer.start(5000); | |
textEdit.show(); | |
return app.exec(); | |
} | |
// output: | |
/* | |
MyTimer::timerEvent | |
timerstart | |
update | |
paintEvent | |
timerEvent | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment