Results 1 to 7 of 7

Thread: Changing the colour of an individual widget

  1. #1
    Join Date
    May 2006
    Location
    Australia
    Posts
    53
    Thanks
    11
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Changing the colour of an individual widget

    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
    Qt Code:
    1. int main(int argc, char*[] argv)
    2. {
    3. QApplication app(argc, argv);
    4. app.QApplication::setStyle(new TopLayoutStyle);
    5. .....
    6. MyTabWidget* topRight = new MyTabWidget();
    7. MyQPalette* palette = topRight->getPalette();
    8. palette->changeColour();
    9. topRight->QWidget::setPalette(bottomColours);
    10. .......
    11. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. MyQPalette::changeColour()
    2. {
    3. QColor greenShadow(98, 161, 98);
    4. QColor green(112, 181, 112);
    5. QColor greenLight(116, 195, 116);
    6. QColor greenMid(95,135,95);
    7. QColor greenForeground(167, 210, 183, 63);
    8. QColor greenDark(80, 140, 80);
    9. QColor midYellow(255, 235, 0);
    10.  
    11. this->setBrush(QPalette::BrightText,greenForeground);
    12. this->setBrush(QPalette::Base, green);
    13. this->setBrush(QPalette::Highlight, greenForeground);
    14. this->setBrush(QPalette::Background, green);
    15. this->setBrush(QPalette::Light, greenLight);
    16. this->setBrush(QPalette::Mid, greenMid);
    17. this->setBrush(QPalette::Dark, greenDark);
    18. this->setBrush(QPalette::Button, green);
    19. this->setBrush(QPalette::Window, green);
    20. }
    To copy to clipboard, switch view to plain text mode 
    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
    Attached Images Attached Images
    Last edited by georgie; 1st May 2006 at 02:00.

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Changing the colour of an individual widget

    Maiby this
    Qt Code:
    1. topRight->setPalette(bottomColours);
    To copy to clipboard, switch view to plain text mode 
    a life without programming is like an empty bottle

  3. #3
    Join Date
    May 2006
    Location
    Australia
    Posts
    53
    Thanks
    11
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Changing the colour of an individual widget

    i switched

    topRight->QWidget::setPalette(bottomColours);

    to

    topRight->setPalette(bottomColours);

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

  4. #4
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Changing the colour of an individual widget

    Emm..posted code is not ehough..bottomColours what is it?
    a life without programming is like an empty bottle

  5. #5
    Join Date
    May 2006
    Location
    Australia
    Posts
    53
    Thanks
    11
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Changing the colour of an individual widget

    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?

  6. #6
    Join Date
    Jan 2006
    Location
    Cambridge, MA
    Posts
    32
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Changing the colour of an individual widget

    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

  7. The following 2 users say thank you to Glitch for this useful post:

    georgie (2nd May 2006), mhoover (3rd May 2006)

  8. #7
    Join Date
    May 2006
    Location
    Australia
    Posts
    53
    Thanks
    11
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Changing the colour of an individual widget

    YOU ARE MY HERO

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

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. Replies: 1
    Last Post: 8th February 2009, 11:37
  3. Changing QPushButton text colour with mouseMoveEvent
    By Misenko in forum Qt Programming
    Replies: 1
    Last Post: 10th June 2008, 16:53
  4. Changing colour thru qss file
    By phillip_Qt in forum Qt Programming
    Replies: 3
    Last Post: 27th March 2008, 05:36
  5. Dynamically changing QLabel background colour
    By T4ng10r in forum Qt Programming
    Replies: 19
    Last Post: 19th April 2007, 12:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.