+ Reply to Thread
Results 1 to 8 of 8

Thread: how to change QGroupBox frame color? (Qt4)

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,317
    Thanks
    20
    Thanked 377 Times in 371 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default how to change QGroupBox frame color? (Qt4)

    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.

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 79 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to change QGroupBox frame color? (Qt4)

    use QPalette. I think QPalette::Window should help or use BackgroundRole.

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,506 Times in 1,384 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to change QGroupBox frame color? (Qt4)

    It the frame is sunken, use QPalette:: Dark, otherwise use QPalette::Light.

    Qt Code:
    1. QPalette p = groupBox->palette();
    2. p.setColor(QPalette::Dark, Qt::white);
    3. groupBox->setPalette(p);
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    J-P Nurmi

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,317
    Thanks
    20
    Thanked 377 Times in 371 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to change QGroupBox frame color? (Qt4)

    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?

  5. #5
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post Re: how to change QGroupBox frame color? (Qt4)

    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

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,506 Times in 1,384 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to change QGroupBox frame color? (Qt4)

    Quote Originally Posted by high_flyer
    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:
    Qt Code:
    1. QPalette p = groupBox->palette();
    2. p.setColor(QPalette::Window, Qt::red);
    3. p.setColor(QPalette::Highlight, Qt::red);
    4. groupBox->setPalette(p);
    To copy to clipboard, switch view to plain text mode 

    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..
    Attached Images Attached Images
    J-P Nurmi

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,317
    Thanks
    20
    Thanked 377 Times in 371 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to change QGroupBox frame color? (Qt4)

    I just found out that this code works where the other code snippets you suggested didn't work for me:
    Qt Code:
    1. //grpControls is a QGroupBox which is parented to another widget
    2. palette.setColor(grpControls->backgroundRole(), QColor(0,255,255));
    To copy to clipboard, switch view to plain text mode 
    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!

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,317
    Thanks
    20
    Thanked 377 Times in 371 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to change QGroupBox frame color? (Qt4)

    @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!

+ Reply to Thread

Similar Threads

  1. Change the shape of a frame.
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 13th November 2007, 06:40
  2. Change frame rate
    By superutsav in forum General Programming
    Replies: 1
    Last Post: 3rd August 2006, 21:02

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