Qt-interest Archive, April 2007
AW: Re: setting text color in a QComboBox
Message 1 in thread
My mistake, you can indeed change the highlight color of the menu to be different than the button of the combo
After you set the palette on the combo you can do the following:
QAbstractItemView *popup = view();
p = popup->palette();
p.setColor(QPalette::Highlight, Qt::white);
p.setColor(QPalette::HighlightedText, Qt::darkCyan);
popup->setPalette(p);
Looks like we have a solution for palettes only (except in the cleanlooks style, where there is still a bug).
YMMV,
Susan
----- Original Message ----
From: Susan Macchia <susan@xxxxxxxxxxxx>
To: Susan Macchia <susan@xxxxxxxxxxxx>
Cc: qt-interest@xxxxxxxxxxxxx
Sent: Friday, April 27, 2007 10:01:07 AM
Subject: Re: setting text color in a QComboBox
In working with the trolls on these issues, it turns out there is only one real bug. In cleanlooks style, using the palette on the combo box view to change the menu item text and background doesn't work.
However for other sytles, setting the palette on the view or the combo box using QPalette::Base and QPalette::Text does indeed work. Because the docs say that QPalette::Base is used for "the background color for text entry widgets", and QPalette::Text is the foreground color used with Qt::Base., I never even thought to use Base/Text.
So if you want to use a palette exclusively you can:
QPalette p = combo->palette();
// Outline around the menu
p.setColor(QPalette::Window, Qt::red);
p.setColor(QPalette::WindowText, Qt::white);
// combo button
p.setColor(QPalette::Button, Qt::darkCyan);
p.setColor(QPalette::ButtonText, Qt::white);
// combo menu
p.setColor(QPalette::Base, Qt::darkCyan);
p.setColor(QPalette::Text, Qt::white);
// highlight button & menu
p.setColor(QPalette::Highlight, Qt::blue);
p.setColor(QPalette::HighlightedText, Qt::red);
// to customize the disabled color
p.setColor(QPalette::Disabled, QPalette::Button, Qt::gray);
p.setColor(QPalette::Disabled, QPalette::ButtonText, Qt::lightGray);
combo->setPalette(p);
NOTE: In Plastique, if you want the button highlight color (QPalette::Hightlight) to be different from the menu, I haven't found a way to do this. Setting the highlight colors using the palette on QComboBox::view doesn't seem to work.
FWIW,
Susan
----- Original Message ----
From: Susan Macchia <susan@xxxxxxxxxxxx>
To: Mark Thompson <mark@xxxxxxxxxxxx>
Cc: qt-interest@xxxxxxxxxxxxx
Sent: Tuesday, April 24, 2007 1:38:28 PM
Subject: Re: setting text color in a QComboBox
I have attached a compilable test program that shows all the ways to set the
colors in combo boxes (that I know of). It also shows the bug trying to use
only QPalette to set the foreground/background colors in the menu of the combo
(the trolls are aware of this bug and are actively working it).
--Susan
----- Original Message ----
From: Mark Thompson <mark@xxxxxxxxxxxx>
To: susan@xxxxxxxxxxxx
Cc: qt-interest@xxxxxxxxxxxxx
Sent: Tuesday, April 24, 2007 12:40:36 PM
Subject: Re: setting text color in a QComboBox
Susan,
Thanks, that helps a lot.
I would certainly like to see a couple of examples.
Mark
susan@xxxxxxxxxxxx wrote:
> Assuming Qt4.
>
> Are you trying to set the text in the button portion or the menu? If you're
trying to set it in the button portion of the combo box, you need to:
>
> QPalette p = combo->palette()
> p.setColor(QPalette::ButtonText, <your color>);
> combo->setPalette(p);
>
> If you're trying to change the text in the menus, that is a bit problematic
because there is a bug in using the palette to change the text or background in
the menu (i.e., QComboBox::view()) of the combo box. You can use a style sheet
instead:
>
> QString styleSheet = "QComboBox { color: <yourcolor>; }";
> combo->setStyleSheet(styleSheet);
>
> HTH,
> Susan
>
> P.S. If you need more detailed help on this, I can provide more detailed
examples. The app that I am working on has many custom colors so I've had to
set combo box colors not only for active states, but disabled, seletion
(highlight), etc.
>
> ----- Original Message ----
> From: Mark Thompson <mark@xxxxxxxxxxxx>
> To: qt-interest@xxxxxxxxxxxxx
> Sent: Tuesday, April 24, 2007 11:51:50 AM
> Subject: setting text color in a QComboBox
>
> Hi,
> Sorry if this is a lame question; I've dug through the help and can't
> seem to figure it out.
>
> I want to change the color of the text listed in a QComboBox.
> Is this possible?
>
> Mark
>
>
--
[ signature omitted ]