I add a very simple test paintEvent function to my class MainWindow ( subclass from QMainWindow).
The problem is that , the function paintEvent hasn’t been invoked when I move another window ontop the MainWindow. It is only invoked when the main window is re-sized or change focus to/from another window. But, even the eventPaint function isn’t invoked, the content I draw inside the MainWindow::paintEvent still hasn’t been erased by the other window that covers it.
So, does it mean that the window system has stored the content when the window is obscured and then revealed ?
Can I disable this ?
Why do you want to disable such a feature? And why are you interested in being covered by other windows?
Redrawing a widget that hasn’t changed is just wasting CPU cycles, that’s why any modern windowing system will cache toplevel windows contents and never ask them to redraw even if they get obscured.
thanks. I just want to see if eventPaint of QWidget will be invoked or not , when the widget is obscured, in this very simple case.
In another more complicated program, I have a viewer class subclass from QWidget, and draw view content in eventPaint. However, the viewer window is partially erased when another window obscure it. I find that the eventPaint has not been invoked. However, the viewer can redraw normally when I resize the window. Here, I hope the window can redraw after obscured by another window.
So, does it mean that the window system has stored the content when the window is obscured and then revealed ? Can I disable this ?
this is the so called double buffering of Qt. Qt has a pixel buffer for each top level widget and each widget draws to this buffer. After all widgets have finished their drawing, the double buffer is blitted to the screen which reduces flickeing and unnessacary repaints which always need calculation (clipping, etc). This feature can be disabled by some widghets attrinbutes, have a look at QWidget::setAttribute [doc.qt.nokia.com]