I'm trying to figure out how long it takes my QGraphicsView to redraw. I have tried the following:
QElapsedTimer timer;
timer.start();
complexViewTransformation();
qDebug() << timer.elapsed();
The problem is that I am getting very small results of 0 to 3 milliseconds, even though the content is visually stuttering. I think the small results happen because redrawing doesn't occur until the application re-enters the event loop. So how can I measure how long the redrawing actually takes?
I don't think that the bottleneck is in your method / placeholder complexViewTransformation()
, because the actual drawing is done behind the scenes within the paint event of the view. In this event, the view draws everything which needs to be drawn (any items which are within the region to be updated).
If you inherit from QGraphicsView, you can reimplement paintEvent and measure how long a call to the original QGraphicsView::paintEvent takes:
class MyGraphicsView : public QGraphicsView {
{
//...
protected:
void paintEvent(QPaintEvent *e)
{
QElapsedTimer timer;
timer.start();
// call the "real" paint event
QGraphicsView::paintEvent(e);
qDebug() << timer.elapsed();
}
};