GraphWidget example: use QBasicTimer instead of raw timer IDs

Change-Id: I9ba66ff37112b749d29a9121f4c89cab1a8e9d07
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Ahmad Samir 2024-09-05 16:54:40 +03:00
parent c07c414609
commit 07593900dc
2 changed files with 8 additions and 7 deletions

View File

@ -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]

View File

@ -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]