Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Styling QGroupBox in Qt Design
Forum Update on Monday, May 27th 2025

Styling QGroupBox in Qt Design

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 22.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KelvinSP
    wrote on last edited by
    #1

    If it is possible, how can I achieve the following result using the stylesheet property (CSS) in Qt Design?

    alt text

    I'm trying to use the following CSS:

    QGroupBox  {
        border: 1px solid gray;
        border-color: #FF17365D;
        margin-top: 27px;
        font-size: 14px;
        border-radius: 15px;
    }
    
    QGroupBox::title  {
        subcontrol-origin: margin;
        subcontrol-position: top center;
        padding: 5px 8000px 5px 8000px;
        background-color: #FF17365D;
        color: rgb(255, 255, 255);
    }
    

    But I'm getting this result:

    alt text

    I'm using Qt 5.3.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      From your description, these QGroupBox seem to be top level widgets, is that correct ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      K 1 Reply Last reply
      0
      • Vinod KuntojiV Offline
        Vinod KuntojiV Offline
        Vinod Kuntoji
        wrote on last edited by Vinod Kuntoji
        #3

        @KelvinSP ,

        Try this stylesheet.

        QGroupBox {
        border: 1px solid gray;
        border-color: #FF17365D;
        margin-top: 27px;
        font-size: 14px;
        border-radius: 15px;
        }
        QGroupBox::title {
        border-top-left-radius: 9px;
        border-top-right-radius: 9px;
        padding: 2px 82px;
        background-color: #FF17365D;
        color: rgb(255, 255, 255);
        }

        C++, Qt, Qt Quick Developer,
        PthinkS, Bangalore

        K 1 Reply Last reply
        3
        • SGaistS SGaist

          Hi,

          From your description, these QGroupBox seem to be top level widgets, is that correct ?

          K Offline
          K Offline
          KelvinSP
          wrote on last edited by KelvinSP
          #4

          Hi @SGaist , what do you mean with top level widgets? Is it a widget without a parent? If this is correct, in this example they are top level widgets, but in my application, they are not. I pretend to apply the stylesheet to the parent so it is applied to the children.

          1 Reply Last reply
          0
          • Vinod KuntojiV Vinod Kuntoji

            @KelvinSP ,

            Try this stylesheet.

            QGroupBox {
            border: 1px solid gray;
            border-color: #FF17365D;
            margin-top: 27px;
            font-size: 14px;
            border-radius: 15px;
            }
            QGroupBox::title {
            border-top-left-radius: 9px;
            border-top-right-radius: 9px;
            padding: 2px 82px;
            background-color: #FF17365D;
            color: rgb(255, 255, 255);
            }

            K Offline
            K Offline
            KelvinSP
            wrote on last edited by KelvinSP
            #5

            Thanks a lot @Vinod-Kuntoji. I have tried to apply the stylesheet that you suggested and I got the following result:

            alt text

            Changing your example to the following CSS:

            QGroupBox {
                border: 1px solid gray;
                border-color: #FF17365D;
                margin-top: 27px;
                font-size: 14px;
                border-bottom-left-radius: 15px;
                border-bottom-right-radius: 15px;
            }
            
            QGroupBox::title {
                subcontrol-origin: margin;
                subcontrol-position: top center;
                border-top-left-radius: 15px;
                border-top-right-radius: 15px;
                padding: 5px 150px;
                background-color: #FF17365D;
                color: rgb(255, 255, 255);
            }
            

            I got the following result:

            alt text

            It is almost the result that I'm looking for, the only problem is that I have to set the padding (left and right) manually, based on the QGroupBox width (e.g. padding: 5px 150px;). Is there some way that I can set it automatically based on the QGroupBox width?

            EddyE 1 Reply Last reply
            1
            • Vinod KuntojiV Offline
              Vinod KuntojiV Offline
              Vinod Kuntoji
              wrote on last edited by
              #6

              @KelvinSP ,

              Sorry. I didn't set the layout.

              C++, Qt, Qt Quick Developer,
              PthinkS, Bangalore

              1 Reply Last reply
              0
              • K KelvinSP

                Thanks a lot @Vinod-Kuntoji. I have tried to apply the stylesheet that you suggested and I got the following result:

                alt text

                Changing your example to the following CSS:

                QGroupBox {
                    border: 1px solid gray;
                    border-color: #FF17365D;
                    margin-top: 27px;
                    font-size: 14px;
                    border-bottom-left-radius: 15px;
                    border-bottom-right-radius: 15px;
                }
                
                QGroupBox::title {
                    subcontrol-origin: margin;
                    subcontrol-position: top center;
                    border-top-left-radius: 15px;
                    border-top-right-radius: 15px;
                    padding: 5px 150px;
                    background-color: #FF17365D;
                    color: rgb(255, 255, 255);
                }
                

                I got the following result:

                alt text

                It is almost the result that I'm looking for, the only problem is that I have to set the padding (left and right) manually, based on the QGroupBox width (e.g. padding: 5px 150px;). Is there some way that I can set it automatically based on the QGroupBox width?

                EddyE Offline
                EddyE Offline
                Eddy
                wrote on last edited by Eddy
                #7

                @KelvinSP said in Styling QGroupBox in Qt Design:

                Is there some way that I can set it automatically based on the QGroupBox width?

                AFAIK there is not.
                You could try another path : combining 2 widgets : top widget = title = QLabel with text and bottom widget = QFrame.

                Hope it helps.

                Eddy

                Qt Certified Specialist
                www.edalsolutions.be

                K 1 Reply Last reply
                3
                • EddyE Eddy

                  @KelvinSP said in Styling QGroupBox in Qt Design:

                  Is there some way that I can set it automatically based on the QGroupBox width?

                  AFAIK there is not.
                  You could try another path : combining 2 widgets : top widget = title = QLabel with text and bottom widget = QFrame.

                  Hope it helps.

                  Eddy

                  K Offline
                  K Offline
                  KelvinSP
                  wrote on last edited by KelvinSP
                  #8

                  Thank you so much @Eddy. By following your tip I got the expected result using a QLabel and a QFrame.

                  alt text

                  I have added a vertical layout and inside it, I have added a QLabel (top) and a QFrame (bottom), and set the following CSS:

                  QLabel {
                          qproperty-alignment: AlignCenter;
                  	border: 1px solid #FF17365D;
                  	border-top-left-radius: 15px;
                  	border-top-right-radius: 15px;
                  	background-color: #FF17365D;
                  	padding: 5px 0px;
                  	color: rgb(255, 255, 255);
                  	max-height: 25px;
                          font-size: 14px;
                  }
                  
                  QFrame {
                  	border: 1px solid #FF17365D;
                  	border-bottom-left-radius: 15px;
                  	border-bottom-right-radius: 15px;
                  }
                  

                  The only issue is that I already have some QGroupBox in my application, but I'm sure I can change it easily. Thanks again.

                  1 Reply Last reply
                  1
                  • EddyE Offline
                    EddyE Offline
                    Eddy
                    wrote on last edited by
                    #9

                    Well done.
                    Glad I could help.

                    Qt Certified Specialist
                    www.edalsolutions.be

                    1 Reply Last reply
                    1

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved