O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Have a go hero – Caching the oscillogram in a pixmap

Now, it should be very easy for you to implement this approach for our example widget. The main difference is that each change to the plot contents should not result in a call to update() but in a call that will rerender the pixmap and then call update(). The paintEvent method then becomes simply this:

void Widget::paintEvent(QPaintEvent *event)
{
    QRect exposedRect = event->rect();
    QPainter painter(this);
    painter.drawPixmap(exposedRect, m_pixmap, exposedRect);
} 

You'll also need to rerender the pixmap when the widget is resized. This can be done from within the resizeEvent() virtual function.

While it is useful to master the available approaches to optimization, it's always important to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required