July 10, 2011

qteruk qteruk
Lab Rat
2 posts

about paintEvent

 

Hello everyone,

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 ?

Thanks

4 replies

July 10, 2011

peppe peppe
Ant Farmer
1025 posts

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.

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

July 10, 2011

qteruk qteruk
Lab Rat
2 posts

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.

July 11, 2011

ZapB ZapB
Robot Herder
1354 posts

Why do you want to waste time redrawing if the contents have not changed and the offscreen buffer will suffice?

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

July 15, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts
qteruk wrote:
So, does it mean that the window system has stored the content when the window is obscured and then revealed ? Can I disable this ?

Hi,

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]

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

 
  ‹‹ [Proposal to Nokia/Qt] Create a "Qt Runtime"      [Solved] How to reflect an image at a label? ››

You must log in to post a reply. Not a member yet? Register here!