Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, May 2007
Re: setting text color in a QComboBox


Message 1 in thread

Thanks again to Susan Macchia for information on setting colors in 
ComboBox....

Now, I'm stuck on setting colors in buttons  (yikes!).

Qt 4.2

I want a simple push button where I can set the color of the button 
itself (no text is necessary).
I can get the text to change color using this:

    QPalette p = button->palette();
    p.setColor(QPalette::ButtonText, myColor);
    button->setPalette(p);

However, I cannot get the button itself to change color (no matter which 
of the ColorRole values I try).

Any help is greatly appreciated!

Ultimately what I'm after is a set of colored buttons.  The user clicks 
a button, selects a new color, and the button color is changed.

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
>
>   

--
 [ signature omitted ] 

Message 2 in thread


Mark Thompson wrote:
>
> Thanks again to Susan Macchia for information on setting colors in 
> ComboBox....
>
> Now, I'm stuck on setting colors in buttons  (yikes!).
>
> Qt 4.2
>
> I want a simple push button where I can set the color of the button 
> itself (no text is necessary).
> I can get the text to change color using this:
>
>    QPalette p = button->palette();
>    p.setColor(QPalette::ButtonText, myColor);
>    button->setPalette(p);
>
> However, I cannot get the button itself to change color (no matter 
> which of the ColorRole values I try).
>
> Any help is greatly appreciated!
>
> Ultimately what I'm after is a set of colored buttons.  The user 
> clicks a button, selects a new color, and the button color is changed.
>
> 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
>>
>>   
>
> -- 
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>

-- 
 [ signature omitted ] 

Message 3 in thread

This is one of those pain in the butt to track down issues :)
 
But luckily, my previous pain is your gift :)
 
I bet your using Windows XP?  In windows XP the 4.2 (and 3.3) styles dont for what ever reason, use the palette for the background color... I believe it uses an image (I solved this about 2+ years ago so the details are a bit vague)
 
So there are two solutions... First, you can create your own WindowsXP derived style, and override the buttons functionality (hard solution).  Calling the following functionality will allow it to work as well
 
button->setStyle( QStyleFactory::create( "Windows" ) );
 
which WILL change the frame and some other minor details, however, it will allow you to color your buttons.
 
Scott

________________________________

From: Mark Thompson [mailto:mark@xxxxxxxxxxxx]
Sent: Fri 5/4/2007 1:16 PM
To: susan@xxxxxxxxxxxx
Cc: qt-interest@xxxxxxxxxxxxx
Subject: Re: setting text color in a QComboBox




Thanks again to Susan Macchia for information on setting colors in
ComboBox....

Now, I'm stuck on setting colors in buttons  (yikes!).

Qt 4.2

I want a simple push button where I can set the color of the button
itself (no text is necessary).
I can get the text to change color using this:

    QPalette p = button->palette();
    p.setColor(QPalette::ButtonText, myColor);
    button->setPalette(p);

However, I cannot get the button itself to change color (no matter which
of the ColorRole values I try).

Any help is greatly appreciated!

Ultimately what I'm after is a set of colored buttons.  The user clicks
a button, selects a new color, and the button color is changed.

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
>
>  

--
 [ signature omitted ] 

Message 4 in thread

Try:
    p.setColor(QPalette::Button, yourColor);

This should do the trick.  If you're making sweeping changes in colors across the entire app, I have learned that it is easier to do this in a derived style (FWIW), which I have since converted all my code to do.  Still using the palette, but inside the style instead of inside a derivation of a QWidget control.

HTH,
Susan


----- Original Message ----
From: Mark Thompson <mark@xxxxxxxxxxxx>
To: susan@xxxxxxxxxxxx
Cc: qt-interest@xxxxxxxxxxxxx
Sent: Friday, May 4, 2007 4:16:22 PM
Subject: Re: setting text color in a QComboBox


Thanks again to Susan Macchia for information on setting colors in 
ComboBox....

Now, I'm stuck on setting colors in buttons  (yikes!).

Qt 4.2

I want a simple push button where I can set the color of the button 
itself (no text is necessary).
I can get the text to change color using this:

    QPalette p = button->palette();
    p.setColor(QPalette::ButtonText, myColor);
    button->setPalette(p);

However, I cannot get the button itself to change color (no matter which 
of the ColorRole values I try).

Any help is greatly appreciated!

Ultimately what I'm after is a set of colored buttons.  The user clicks 
a button, selects a new color, and the button color is changed.

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
>
>   

--
 [ signature omitted ]