Set color of QWidget
-
Hellow, i have one problem:
I need to set color of QWidget, how can i do it without QSS
I try
@ QPalette * p = new QPalette;
p->setColor(QPalette::Window, Qt::red);
w->setPalette(*p);@
@ QPalette * p = new QPalette;
p->setColor(QPalette::Background, Qt::red);
w->setPalette(*p);@
@ QPalette * p = new QPalette;
p->setColor(w->foregroundRole() , Qt::red);
w->setPalette(*p);@
@ QPalette * p = new QPalette;
p->setColor(w->backgroundRole() , Qt::red);
w->setPalette(*p);@
w is a object of QWidget
But it is all doesnt work -
Instead you can try to do it using stylesheets. It should be something like this:
@
w->setStyleSheet("background-color:red;");
@Edit: Sorry I saw that you do not want to use QSS too late.
@
QPalette p(palette());
p.setColor(QPalette::Background, Qt::red);
w->setAutoFillBackground(true);
w->setPalette(p);
@For more details please check "this article":http://developer.qt.nokia.com/wiki/How_to_Change_the_Background_Color_of_QWidget
-
You are welcome! Sorry again for my first proposition - I rushed to answer without having read the question carefully :)