One approach you can take is to always draw a pixmap, but remember to recreate the pixmap “soon” if the window size has changed.
So, when paintEvent appears, if the size differs from the current pixmap size, then color the saved pixmap anyway, but then set (or reset) a QTimer to trigger a signal in the slot that will update pixmap.
When this update method is launched, it will re-render the pixmap and request a widget update.
source share