0

Suppose I have an area on the screen defined with global screen coordinates. There is a widget (top level window) that moves into that area (using standard animation techniques). I'd like to clip out the part of the widget that happens to be outside of the screen defined area until it fully enters that area, i.e. I only want the widget to be drawn inside that rectangle.

One possible sub-optimal solution is to call update() whenever widgets position changes, then in paintEvent I can calculate and set relevant local clipping on QPainter. However it would be very inefficient to redraw the entire window just because it moved on the screen. Essentially my question boils down to whether it's possible to set global clipping region on a widget?

pullo_van
  • 649
  • 6
  • 19

1 Answers1

0

I believe global clipping is not possible. But if you worried about frequent redrawing and your widget content doesn't change often or never you can draw into a QPixmap outside of the paintEvent(). And in the paintEvent(), after calculating the clipped region you just use 'QPainter::drawPixmap()` to rapidly paint your content. That should help with any performance issues.

Aaron
  • 1,181
  • 7
  • 15