PDA

View Full Version : how to change QGroupBox frame color? (Qt4)



high_flyer
8th May 2006, 14:32
Hi,

As the subject says.
I was not able to find any color role that changed the frame color of a QGroupBox, is it really impossible? (i.e do i really need to tweak QSytle for that?)

Thanks.

munna
8th May 2006, 15:11
use QPalette. I think QPalette::Window should help or use BackgroundRole.

jpn
8th May 2006, 18:51
It the frame is sunken, use QPalette:: Dark, otherwise use QPalette::Light.



QPalette p = groupBox->palette();
p.setColor(QPalette::Dark, Qt::white);
groupBox->setPalette(p);

high_flyer
9th May 2006, 11:54
Strange, it does not work for me, not in code, and not in designer...
In your attached image I see you are working under windows... (I am under SUSE10)
Maybe its a window system issue?

nupul
9th May 2006, 13:22
I confirm that this code works on SuSE 10...try the following link

http://www.qtcentre.org/forum/showthread.php?t=2041

it's the same doubt that you posted!!!

This is in my code and it works

grpbox_right->setPalette(QPalette(Qt::darkBlue));

Nupul

jpn
9th May 2006, 13:43
Strange, it does not work for me, not in code, and not in designer...
In your attached image I see you are working under windows... (I am under SUSE10)
Maybe its a window system issue?
Plastique style maybe? Then try:


QPalette p = groupBox->palette();
p.setColor(QPalette::Window, Qt::red);
p.setColor(QPalette::Highlight, Qt::red);
groupBox->setPalette(p);


QWindowsStyle lets QCommonStyle to draw PE_Frame primitive element. That's where I got the color group I advised to use. But anyway, it seems to depend on the used style. Such a pity, but for example QPlastiqueStyle seems to use a different color group for drawing frame rect...

You can check QxxxStyle::drawPrimitive()'s case PE_Frame for more information. :)
QPlastiqueStyle uses a merged color of darkened background palette color and highlight palette color or something like that..

high_flyer
9th May 2006, 13:45
I just found out that this code works where the other code snippets you suggested didn't work for me:


//grpControls is a QGroupBox which is parented to another widget
palette.setColor(grpControls->backgroundRole(), QColor(0,255,255));
In all the code you supplied the group box was not parented, or its parent was not visible in the code supplied... I think it plays a role in this behaviour.
Another thing that bothers me is when I try to set the frame color with designer no color role changes the frame color...
Can you confirm this?

Thanks for your help!

high_flyer
9th May 2006, 13:48
@jpn
Yes, your last reply was the right answer!
Its the Plastique, and when I try this with another stlyle its behaves as expected.
Tanks!