Results 1 to 2 of 2

Thread: QGroupBox image in title

  1. #1
    Join Date
    Jul 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default QGroupBox image in title

    Hey Guys,

    I'm trying to style my QGroupBox a little.
    What I've done yet:

    Qt Code:
    1.  
    2. background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
    3. stop: 0 #E0E0E0, stop: 1 #FFFFFF);
    4. border: 2px solid rgb(66, 66, 66);
    5. border-top: 30px solid rgb(66, 66, 66);
    6.  
    7.  
    8. border-bottom-right-radius: 20px;
    9. border-bottom-left-radius: 20px;
    10. margin-top: 0ex; /* leave space at the top for the title */
    11. font-weight: bold;
    12. }
    13.  
    14. QGroupBox::title {
    15.  
    16. subcontrol-origin: margin;
    17. subcontrol-position: top left; /* position at the top center */
    18.  
    19. background-color: rgb(66, 66, 66);
    20. color: rgb(255, 255, 255);
    21. padding: 8 10px;
    22. }
    To copy to clipboard, switch view to plain text mode 

    That looks good for me, but what i would like to have is an image left of the title.
    Any ideas how to do that?

    Thanks in advance.

    LG from germany

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: QGroupBox image in title

    AFAIK, you can't since QGroupBox exposes the title as QString (even if internally its probably a QLabel).
    You can try to "cheat", by setting a background image for the titles, which will be as wide as the string + the image you want to have, but will depict the image you want only on the right side, and the rest fill with transparent or background color, so that the title string will be visible on top of it.
    If this doesn't work, you will probably have to subclass QGroupBox.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. customizing QGroupbox title
    By FelixB in forum Newbie
    Replies: 3
    Last Post: 7th February 2014, 16:24
  2. QGroupBox's title
    By lzpmail in forum Newbie
    Replies: 2
    Last Post: 3rd June 2011, 03:00
  3. QGroupBox title alignment
    By binaural in forum Newbie
    Replies: 2
    Last Post: 9th April 2010, 22:56
  4. How to set color for QGroupBox Title
    By arunvv in forum Qt Programming
    Replies: 5
    Last Post: 4th December 2008, 18:50
  5. QGroupBox title truncated on both sides
    By Gopala Krishna in forum Qt Programming
    Replies: 2
    Last Post: 7th October 2006, 16: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
  •  
Qt is a trademark of The Qt Company.