[Qt-interest] Restoring default widget brush

Nikos Chantziaras realnc at arcor.de
Thu Apr 8 19:54:12 CEST 2010


That should work.  But this shouldn't be needed at all.  There has to be 
a way to reset the brush to its default without doing backups.

On 04/08/2010 03:21 PM, Denis Akhmetzyanov wrote:
> Hi,
> You could save old brush before change:
>
>    QPalette p(this->widget()->palette());
>    QBrush oldBrush = p.brush(QPalette::Base);
>    p.setBrush(QPalette::Base, pixmap);
>    this->widget()->setPalette(p);
> // do something
> ...
> // restore brush
>    p.setBrush(QPalette::Base, oldBrush);
>    this->widget()->setPalette(p);
>
>
> 2010/4/8 Nikos Chantziaras <realnc at arcor.de <mailto:realnc at arcor.de>>
>
>     Suppose I change the brush of a widget like this:
>
>        QPalette p(this->widget()->palette());
>        p.setBrush(QPalette::Base, pixmap);
>        this->widget()->setPalette(p);
>
>     (I *think* this is the correct way of using a pixmap to change the
>     background of a widget to an image.)
>
>     How do I restore the widget background back to its default?  The below
>     segfaults:
>
>        QPalette p(this->widget()->palette());
>        p.setBrush(QPalette::Base, QBrush());
>        this->widget()->setPalette(p);  // <-- crashes



More information about the Qt-interest-old mailing list