PDA

View Full Version : Changing the colour of an individual widget



georgie
1st May 2006, 02:55
ok - I am struggling a bit with my styles......
I want to have a uniform style for the whole application, and then I want to be able to make a couple of the key widgets stand out by changing them to a second style....


basically what I do is



int main(int argc, char*[] argv)
{
QApplication app(argc, argv);
app.QApplication::setStyle(new TopLayoutStyle);
.....
MyTabWidget* topRight = new MyTabWidget();
MyQPalette* palette = topRight->getPalette();
palette->changeColour();
topRight->QWidget::setPalette(bottomColours);
.......
}



MyQPalette::changeColour()
{
QColor greenShadow(98, 161, 98);
QColor green(112, 181, 112);
QColor greenLight(116, 195, 116);
QColor greenMid(95,135,95);
QColor greenForeground(167, 210, 183, 63);
QColor greenDark(80, 140, 80);
QColor midYellow(255, 235, 0);

this->setBrush(QPalette::BrightText,greenForeground);
this->setBrush(QPalette::Base, green);
this->setBrush(QPalette::Highlight, greenForeground);
this->setBrush(QPalette::Background, green);
this->setBrush(QPalette::Light, greenLight);
this->setBrush(QPalette::Mid, greenMid);
this->setBrush(QPalette::Dark, greenDark);
this->setBrush(QPalette::Button, green);
this->setBrush(QPalette::Window, green);
}



now for the most part this is cool, all the buttons/outlines etc change on the tabs widget which I want to stand out....only prob is that the background does not change colour even though everything else does
i've attached a screen shot
I can't work out why the background of the tab widget appears to be filled with the background of the application instead of its own background unhappy

(and yes, I know the screen layout is pretty crappy at the moment - i'm still just experimenting and getting my custom widgets to look right)

thanks guys

zlatko
1st May 2006, 09:18
Maiby this


topRight->setPalette(bottomColours);

georgie
1st May 2006, 09:31
i switched

topRight->QWidget::setPalette(bottomColours);

to

topRight->setPalette(bottomColours);

and it does exactly the same thing....is that what you meant??

zlatko
1st May 2006, 10:26
Emm..posted code is not ehough..bottomColours what is it?

georgie
1st May 2006, 11:56
haha...sorry....clearly I am half asleep

I didn't think my variable names would make sense to anyone but me, so I changed some of the names, but I am dumb so I missed one! sorry for wasting ur time....


anyway, what that line is meant to be is

topRight->QWidget::setPalette(palette);


that makes a bit more sense doesn't it?

Glitch
1st May 2006, 15:13
Georgie,

What version of Qt are you using? Starting with 4.1 the default bahavior for most widgets is to get the background directly from thier parent essentially skipping any type of fill. Most likely you need to call setAutoFillBackground(true) on the widgets that are misbehaving.

--Justin Noel
justin@ics.com

georgie
2nd May 2006, 03:53
YOU ARE MY HERO

i have been staring at that for so freakin long
thankyou
and yeah...it's 4.1 :)