diff options
Diffstat (limited to 'examples/widgets/graphicsview')
-rw-r--r-- | examples/widgets/graphicsview/elasticnodes/graphwidget.cpp | 12 | ||||
-rw-r--r-- | examples/widgets/graphicsview/elasticnodes/graphwidget.h | 3 |
2 files changed, 8 insertions, 7 deletions
diff --git a/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp b/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp index ede3d23137b..9e678c0b38a 100644 --- a/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp +++ b/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp @@ -74,8 +74,10 @@ GraphWidget::GraphWidget(QWidget *parent) //! [2] void GraphWidget::itemMoved() { - if (!timerId) - timerId = startTimer(1000 / 25); + using namespace std::chrono_literals; + + if (!timer.isActive()) + timer.start(1000ms / 25, this); } //! [2] @@ -132,10 +134,8 @@ void GraphWidget::timerEvent(QTimerEvent *event) itemsMoved = true; } - if (!itemsMoved) { - killTimer(timerId); - timerId = 0; - } + if (!itemsMoved) + timer.stop(); } //! [4] diff --git a/examples/widgets/graphicsview/elasticnodes/graphwidget.h b/examples/widgets/graphicsview/elasticnodes/graphwidget.h index a75f5e2bbe3..5f7bc500ac3 100644 --- a/examples/widgets/graphicsview/elasticnodes/graphwidget.h +++ b/examples/widgets/graphicsview/elasticnodes/graphwidget.h @@ -4,6 +4,7 @@ #ifndef GRAPHWIDGET_H #define GRAPHWIDGET_H +#include <QBasicTimer> #include <QGraphicsView> class Node; @@ -34,7 +35,7 @@ protected: void scaleView(qreal scaleFactor); private: - int timerId = 0; + QBasicTimer timer; Node *centerNode; }; //! [0] |