Results 1 to 8 of 8

Thread: QPalette Question

  1. #1
    Join Date
    Nov 2006
    Location
    Los Angeles
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QPalette Question

    Hello,
    I want to define a palette that every widget in my application respects by default.
    As a test, i went ahead and used the static method to fetch the palette from QApplication, made various modifications, and then stuffed it back via QAppication::setPalette. Most widgets seemed to obey the modifications except one: QGroupBox. I cannot seem to change its color through the palette. I think that i have tried every roll listed in QPalette.
    Are there other rolls which arent listed, or is there no guarantee that stock qt widgets will obay the qapplication palette, or am i going about this all wrong?

    Thanks

    jonathan

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPalette Question

    Maybe:
    Qt Code:
    1. groupBox->setAutoFillBackground( true );
    To copy to clipboard, switch view to plain text mode 
    will help?

  3. #3
    Join Date
    Nov 2006
    Location
    Los Angeles
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPalette Question

    Quote Originally Posted by jacek View Post
    Maybe:
    Qt Code:
    1. groupBox->setAutoFillBackground( true );
    To copy to clipboard, switch view to plain text mode 
    will help?
    I will try this but I don't think it makes much sense. What would that have to do with the color of the label and box itself?
    The real question i have is about my understanding of how it should work. Is my notion of the application's palette's scope flawed? Is it not ment to govern everything in an application unless specifically overruled?

    And thank you for the quick reply. I am excited to have found a good forum for qt.

    jonathan

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPalette Question

    Quote Originally Posted by jlgerber View Post
    I will try this but I don't think it makes much sense. What would that have to do with the color of the label and box itself?
    How do you expect to see the colour of something that is completely transparent?

    Quote Originally Posted by jlgerber View Post
    Is it not ment to govern everything in an application unless specifically overruled?
    Yes, but QPalette doesn't control everything. You might have to create your own style to fully customize the appearance of that widget.

  5. #5
    Join Date
    Nov 2006
    Location
    Los Angeles
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPalette Question

    Quote Originally Posted by jacek View Post
    How do you expect to see the colour of something that is completely transparent?


    Yes, but QPalette doesn't control everything. You might have to create your own style to fully customize the appearance of that widget.
    Eh? I am talking about the frame itself. It is a QGroupBox (creates a frame and label around other widgets). And the problem isnt that i cannot see it; the problem is that it does not respond to changes in the application palette, like every other widget in the program.
    I had to do something like this when initializing it to get it to work:

    attrBox = new QGroupBox("Attributes");
    attrBox->setPalette(QApplication::palette() );

    I thought that it would already be initialized with the application's palette.

    It was my understanding that every widget in an application shared the same palette initially. is this not true?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPalette Question

    Quote Originally Posted by jlgerber View Post
    Eh? I am talking about the frame itself. It is a QGroupBox (creates a frame and label around other widgets).
    OK, so we are talking about the frame in sense of a line, not in sense of QFrame.

    Quote Originally Posted by jlgerber View Post
    And the problem isnt that i cannot see it; the problem is that it does not respond to changes in the application palette, like every other widget in the program.
    Consider this program:
    Qt Code:
    1. #include <QApplication>
    2. #include <QGroupBox>
    3. #include <QLayout>
    4. #include <QPalette>
    5. #include <QPushButton>
    6.  
    7. class Test : public QGroupBox
    8. {
    9. Q_OBJECT
    10. public:
    11. Test() : QGroupBox( "test" )
    12. {
    13. QPushButton *b = new QPushButton( "change" );
    14.  
    15. connect( b, SIGNAL( clicked() ), this, SLOT( changePalette() ) );
    16.  
    17. l->addWidget( b );
    18. setLayout( l );
    19. }
    20.  
    21. private slots:
    22. void changePalette()
    23. {
    24. p.setColor( QPalette::Dark, Qt::red );
    25. QApplication::setPalette( p );
    26. update();
    27. }
    28. };
    29.  
    30. int main( int argc, char **argv )
    31. {
    32. QApplication app( argc, argv );
    33.  
    34. Test t;
    35. t.show();
    36.  
    37. return app.exec();
    38. }
    39.  
    40. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    I've attached two screenshots showing group box with original palette and the same group box after the QApplication palette was changed.

    Note that some styles (in this case Plastique) sometimes ignore QPalette settings, so I had to use windows style.
    Attached Images Attached Images

  7. #7
    Join Date
    Nov 2006
    Location
    Los Angeles
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPalette Question

    Quote Originally Posted by jacek View Post
    OK, so we are talking about the frame in sense of a line, not in sense of QFrame.

    .....
    Note that some styles (in this case Plastique) sometimes ignore QPalette settings, so I had to use windows style.
    If you had said THAT in the first place, you could have left the code out I am using the plastique style.. so that would be a bug then?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPalette Question

    Quote Originally Posted by jlgerber View Post
    so that would be a bug then?
    I would call it a "feature". There is/was a similar issue with windows XP style and button colours.

    You can always contact the Trolls and say you would like to able to change that line colour in Plastique too. If this is a common query, they might implement it. Other solution is to implement your own style.

Similar Threads

  1. QTextEdit simple question
    By Marcopolo in forum Qt Tools
    Replies: 4
    Last Post: 11th October 2007, 00:01
  2. QThread exit()/quit() question
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 28th August 2006, 14:38
  3. Beginner C++ question
    By masoroso in forum General Programming
    Replies: 2
    Last Post: 19th April 2006, 14:15
  4. QPalette won't set QLabel's Window & Foreground color
    By koklim in forum Qt Programming
    Replies: 6
    Last Post: 23rd January 2006, 10:27
  5. xml with binary question
    By TheKedge in forum Qt Programming
    Replies: 7
    Last Post: 12th January 2006, 23:21

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.