[Qt-interest] Best Way To Force Complete Repaint of Widget
Andre Somers
andre at familiesomers.nl
Tue Oct 6 10:54:29 CEST 2009
Willy P wrote:
> I'm encountering some pretty nasty bugs embedding widgets in OpenGL
> scenes. They are not updating properly and there are some bad
> blending issues with the scene behind it. However, they work
> perfectly on total repaint situations, ie when you cover the widget
> with another window and then show it again.
>
> So my question is, how do I force a *total* repaint of the widget and
> all it's children every time it needs to be updated? It's not a big
> widget so I'm not concerned w/ the performance issues.
>
> I've tried this, but it only sort of solves my problem:
>
> void MyWidget::paintEvent( QPaintEvent* pe )
> {
> qDebug() << "painting";
>
> if( pe->rect() != rect() ) {
> pe->accept();
> repaint( rect() );
> } else {
> QWidget::paintEvent( pe );
> }
> }
>
> I say sort of, b/c it works if any child widgets are embedded in
> layouts, they do not get updated.
>
> -Willy
>
> PS: This only seems to be a problem on Mac, Windows works fine.
>
>
In that case, why not iterate over the child widgets and force a repaint
on them too?
Something like:
QList<QWidget *> widgets = parentWidget.findChildren<QWidget *>();
foreach (QWidget* w, widgets)
w->repaint(rect());
If it is only nessecairy on Mac, then I would make sure it is only done
on Mac too. Use conditional compilation for that.
André
More information about the Qt-interest-old
mailing list