PDA

View Full Version : how to draw background color of a label



gauravg
1st November 2011, 04:16
hi all
pls tell me how to draw background color of a label.(ie background color of a label is blue and text of label is white)



thanks with regards:
gauravg

Santosh Reddy
1st November 2011, 04:46
Here you go, using QPalette

//main.cpp
#include <QtGui>
//QLabel background
class MyWidget : public QLabel
{
public:
MyWidget(QWidget* parent = 0) : QLabel(parent)
{
setText("QLabel");
QPalette p = palette();
p.setColor(QPalette::Window, Qt::blue);
p.setColor(QPalette::WindowText, Qt::white);
setPalette(p);
}
};


int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyWidget w;
w.show();
return a.exec();
}
#include "main.moc"