0

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?

Anthony
  • 8,570
  • 3
  • 38
  • 46

1 Answers1

4

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();
    }
};
leemes
  • 44,967
  • 21
  • 135
  • 183
  • Thanks! Do you have any idea if this would take into account style sheets? For example, say I have a style sheet to make a fancy gradient background, and I want to measure the performance impact. – Anthony May 22 '12 at 04:47
  • I don't know exactly, but I'd say yes. `paintEvent` draws everything, including the background of the widget itself. – leemes May 22 '12 at 11:09