Results 1 to 4 of 4

Thread: customizing QGroupbox title

  1. #1
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default customizing QGroupbox title

    Hi,

    I want to customize the title of a QGroupBox by using a stylesheet. See the desired result in the attached image (qgroupbox_desired.png). A almost have the layout, but the title background is too small (qgroupbox_wrong_title.png). how can I extend the title over the whole width?

    my stylesheet:
    Qt Code:
    1. {
    2. background-color:transparent;
    3. border-bottom-left-radius: 3px;
    4. border-bottom-right-radius: 3px;
    5. border: 1px solid #acacac;
    6. border-top: none;
    7. margin-top: 5px;
    8. }
    9.  
    10. QGroupBox::title
    11. {
    12. subcontrol-origin: margin;
    13. background:url(:/assets/subWindowBackground);
    14. border-top-left-radius: 3px;
    15. border-top-right-radius: 3px;
    16. border: 1px solid #0b477b;
    17. border-bottom: none;
    18. background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
    19. stop: 0 #005192, stop: 1 #002f60);
    20. padding: 2 2px;
    21. color: white;
    22. }
    To copy to clipboard, switch view to plain text mode 

    thanks in advance!
    Felix
    Attached Images Attached Images

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: customizing QGroupbox title

    As style sheets work on the area of widget, it may not be directly possible to do so. To do so, title sub-contol has to increase it's width (or at least it's bacakground width) to QGroupBox's width. I cannot think of a way to make title sub-control aware of QGroupBox's width, but we can use a large padding to the right to make to look like what you want. Try adding padding more than the width of the QGroupBox widget

    Qt Code:
    1. padding: 2 20000 2 2; /* some large value, as QGrouBox actual width is not known */
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Santosh Reddy for this useful post:

    FelixB (19th July 2011)

  4. #3
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: customizing QGroupbox title

    thank you, but I already found a (better?) solution: I created a border image for the QGroupBox with a 25px top-border with the desired color.

    Qt Code:
    1. {
    2. background-color:transparent;
    3. border-image:url(:/assets/QGroupBoxBorder) 25 2 2 2;
    4. border-width: 25px 2px 2px 2px;
    5. }
    6.  
    7. QGroupBox::title
    8. {
    9. background: transparent;
    10. margin: 4px;
    11. color: white;
    12. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  5. #4
    Join Date
    May 2011
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: customizing QGroupbox title

    margin-top

Similar Threads

  1. QGroupBox's title
    By lzpmail in forum Newbie
    Replies: 2
    Last Post: 3rd June 2011, 02:00
  2. QGroupBox title alignment
    By binaural in forum Newbie
    Replies: 2
    Last Post: 9th April 2010, 21:56
  3. How to set color for QGroupBox Title
    By arunvv in forum Qt Programming
    Replies: 5
    Last Post: 4th December 2008, 17:50
  4. QGroupBox title truncated on both sides
    By Gopala Krishna in forum Qt Programming
    Replies: 2
    Last Post: 7th October 2006, 15:02
  5. Customizing Mainwindow's title bar
    By Anitha in forum Qt Programming
    Replies: 3
    Last Post: 13th February 2006, 13:13

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.