PDA

View Full Version : reset the Palette of my QWidget



sattu
7th February 2014, 07:11
Hi everyone,

For setting an image as the background image of my QWidget I am using the following code-



this->setAutoFillBackground(true);
QPalette palette = this->palette();
palette.setBrush(this->backgroundRole(), QBrush(QImage("MyImage.jpg")));
this->setPalette(palette);


Now I want to reset my Palette and make my QWidget appear completely Black. How do I do that?
I tried using
QPixMap and QPixMap::fill(Qt::Black) and then setting this PixMap to my Palette, but it didn't work :(

anda_skoa
7th February 2014, 07:57
If you haven't change the parent's palette, just take that, otherwise take the one from the QApplication instance



setPalette(parentWidget()->palette());
// or
setPalette(QApplication::palette());


Cheers,
_

sattu
12th February 2014, 06:45
If you haven't change the parent's palette, just take that, otherwise take the one from the QApplication instance



setPalette(parentWidget()->palette());
// or
setPalette(QApplication::palette());

_

Sorry for replying late. For the moment what I did is I put a QFrame over the widget I wanted to appear black and made the background of the QFrame as black. So that solved the issue but yes, it's not a good way of doing it.
So I will definitely try what you have written here and will get back if I face any issues.

-Thanks,
Sattu