Results 1 to 3 of 3

Thread: Setting a widget's QPalette to default?

  1. #1
    Join Date
    Oct 2009
    Posts
    7
    Thanks
    3
    Platforms
    Windows

    Default Setting a widget's QPalette to default?

    I want a QLabel whose parent has a custom QPalette to have the default palette. What's the best way of doing that?

    I thought it would just be something like:
    Qt Code:
    1. label->setPalette(p);
    To copy to clipboard, switch view to plain text mode 

    But that doesn't work, label still inherits its parent's palette. Whether that's done before or after its parent's palette has changed from the default.

    I found that
    Qt Code:
    1. c = p.color(QPalette::WindowText);
    2. p.setColor(QPalette::WindowText, c);
    3. label->setPalette(p);
    To copy to clipboard, switch view to plain text mode 
    works. The label than gets the default QPalette::WindowText colour rather than its parent's. But that just confuses me further as I cannot see why the second code snippet would work but not the first.

    So two questions. What is the best way to set a child widget's palette to the default if its parent uses a different palette. And why does the second code snippet have a different result than the first when they look like they should do the same thing?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Setting a widget's QPalette to default?

    take a look at QApplication::palette.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Setting a widget's QPalette to default?

    Qt Code:
    1. // ho crap! no!
    2. my_widget->setPalette( p );
    3.  
    4. // that's better
    5. my_widget->setPalette( my_widget->style()->standardPalette() );
    To copy to clipboard, switch view to plain text mode 

  4. The following 2 users say thank you to elcuco for this useful post:

    luchio (28th February 2013), Spectralist (13th February 2010)

Similar Threads

  1. Replies: 7
    Last Post: 12th January 2011, 22:01
  2. Replies: 1
    Last Post: 30th March 2009, 14:28
  3. Setting stylesheet for "almost" all widgets
    By maverick_pol in forum Qt Programming
    Replies: 10
    Last Post: 14th July 2008, 22:06
  4. Setting default icon for all windows / dialogs
    By steg90 in forum Qt Programming
    Replies: 1
    Last Post: 5th July 2007, 10:04
  5. By default TreeWidget width setting in DockWidget
    By santosh.kumar in forum Qt Programming
    Replies: 0
    Last Post: 31st May 2007, 05:55

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.