View Full Version : QPalette won't set QLabel's Window & Foreground color
koklim
20th January 2006, 11:45
Hi, i am using qt 4.1.0 on a window xp platform. I use the appraoch below to set the label's forefround and Window color but nothing happens. I have serch every where for clues to solve this but to no avale. I greatly appreciate any help. Thanks
QPalette temp;
temp.setColor(QPalette::Foreground, QColor(255, 0, 0));
temp.setColor(QPalette::Window, QColor(0, 0, 0));
for (int i = 0; i < iColSize; i++)
{
ptrLbl = new QLabel(this);
ptrLbl->setObjectName("XXX");
ptrLbl->setGeometry( X,X,X,X );
ptrLbl->setFrameShape( QFrame::StyledPanel );
ptrLbl->setAlignment( int( Qt::AlignLeft ) );
ptrLbl->setMouseTracking(true);
ptrLbl->setPalette(temp);
}
zlatko
20th January 2006, 12:22
at the end you must show your label
ptrLbl->show();
koklim
20th January 2006, 12:51
it didn't work. Just found out that it must be something more.
jacek
20th January 2006, 12:55
Does it work when you use different style?
C:\...> app.exe -style plastique
orb9
23rd January 2006, 00:27
Two problems:
1) QPalette::Foreground is deprecated, use WindowText instead.
2) A label does not have a background in Qt4.1, only the text is drawn. To fill the background automatically you can use setAutoFillBackground(true) on your labels.
QPalette temp;
temp.setColor(QPalette::WindowText, QColor(255, 0, 0));
temp.setColor(QPalette::Window, QColor(0, 0, 0));
for (int i = 0; i < iColSize; i++)
{
ptrLbl = new QLabel(this);
ptrLbl->setObjectName("XXX");
ptrLbl->setAutoFillBackground( true );
ptrLbl->setGeometry( X,X,X,X );
ptrLbl->setFrameShape( QFrame::StyledPanel );
ptrLbl->setAlignment( int( Qt::AlignLeft ) );
ptrLbl->setMouseTracking(true);
ptrLbl->setPalette(temp);
}
Hope this helps.
koklim
23rd January 2006, 02:32
Thanks orb9 for your help. I have yet to try your suggestion. I'll let you know when i have. It is a busy week for me in the office. Again thank you so much. Appreciate your help. :)
koklim
23rd January 2006, 11:27
orb9.....i tried your suggestion and it didn't worked out as we hoped. Thanks for your help. You have beeen very helpful.
Powered by vBulletin® Version 4.2.5 Copyright © 2023 vBulletin Solutions Inc. All rights reserved.