Skip to content

Instantly share code, notes, and snippets.

@arajkumar
Created June 20, 2013 20:27
Show Gist options
  • Save arajkumar/5826302 to your computer and use it in GitHub Desktop.
Save arajkumar/5826302 to your computer and use it in GitHub Desktop.
#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