iig
10th August 2010, 11:30
Hi, all!
Why I can't set QLabel background color when it is in QToolBar?
This is my code:
#include <QtGui>
int main(int argc, char** argv)
{
QApplication app(argc,argv);
QMainWindow w;
QToolBar* bar = new QToolBar();
QLabel* label = new QLabel("TEST");
QPalette pal = label->palette();
pal.setColor(label->backgroundRole(), Qt::green);
label->setPalette(pal);
label->setAutoFillBackground(true);
bar->addWidget(label);
w.addToolBar(bar);
w.show();
app.exec();
return 0;
}
And here are result:
http://img199.imageshack.us/img199/7868/snapshot1sw.png (http://img199.imageshack.us/i/snapshot1sw.png/)
Why I can't set QLabel background color when it is in QToolBar?
This is my code:
#include <QtGui>
int main(int argc, char** argv)
{
QApplication app(argc,argv);
QMainWindow w;
QToolBar* bar = new QToolBar();
QLabel* label = new QLabel("TEST");
QPalette pal = label->palette();
pal.setColor(label->backgroundRole(), Qt::green);
label->setPalette(pal);
label->setAutoFillBackground(true);
bar->addWidget(label);
w.addToolBar(bar);
w.show();
app.exec();
return 0;
}
And here are result:
http://img199.imageshack.us/img199/7868/snapshot1sw.png (http://img199.imageshack.us/i/snapshot1sw.png/)