Is there any way to get the pixels that will be displayed on a QWidget, do some processing, and then display the processed pixels?
I can’t seem to overcome the limitations of paintEvent(), hopefully someone can help.
QPixmap::grabWidget and QWidget::render will get me the pixels I need, but they cannot be called from within paintEvent(), since doing so will trigger an infinite loop.
I have tried running a timer, taking a snapshot, doing my processing, forcing a repaint, and displaying the saved image. This works to some extent, but on dynamic content (i.e. moving) it fails miserably.
I need to be able to do this from within paintEvent().
Is there any way to do this?
It sounds like your problem would be best solved by rendering the widget to a pixmap (within the paint event), doing your processing on the pixmap, then rendering the result to the widget afterwards:
Normally, the technique I’ve described would be considered unnecessary (or even undesirable) because it is essentially a form of double-buffering and
QWidgetalready provides double-buffering behind the scenes. However, in your case you are doing some processing on the drawing before performing a final rendering. As such, this is probably the best approach.