As an exercise, we will modify our oscillogram widget so that it only rerenders the part of its data that is required.
Optimizing widget painting
Time for action – Optimizing oscillogram drawing
The first step is to modify the paint event handling code to fetch information about the region that needs updating and pass it to the method drawing the chart. The changed parts of the code have been highlighted here:
void Widget::paintEvent(QPaintEvent *event) { QRect exposedRect = event->rect(); ... drawSelection(&painter, r, exposedRect); drawChart(&painter, r, exposedRect); painter.restore(); }
The next step is to modify drawSelection() to only draw the part of the selection that intersects...