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. QGroupBox Title Position
Forum Updated to NodeBB v4.3 + New Features

QGroupBox Title Position

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 9.3k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    RRRitchey
    wrote on last edited by
    #1

    I wanted an enclosed box around several lines of text with at title so I chose a QGroupBox that held a VBox layout which held a QLabel with several lines of text. The problem I have is that the top of the title text is even with the QGroupBox frame (so the title is basically inside the frame, not on top as the examples show) and the title overlaps part of the first line of the label text. So, is there a way to correct this? Thanks,

    1 Reply Last reply
    0
    • A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      Can you show the code? Without seeing the code for making the box/frame/layout I can't tell what might be the problem.

      My only guess is that it could be a stylesheet issue. Or it could be the OS you are using, different OSes show group boxes differently. But never in a "buggy" way.

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RRRitchey
        wrote on last edited by
        #3

        OK, here is the code. The page has a logo, a large label for a unit name and then two columns for information. This is where the labels with multiple lines go inside the group boxes.
        !http://i61.tinypic.com/juwjo8.jpg(GroupBoxOverlap)!
        @
        UnitView::UnitView(QWidget* pParent)
        : QWidget(pParent)
        {
        pLabelSF_Logo = new QLabel;
        pLabelSF_Logo->setMinimumWidth(600);
        pLabelSF_Logo->setMinimumHeight(232);
        pLabelSF_Logo->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
        pLabelSF_Logo->setScaledContents(true);
        pLabelSF_Logo->setPixmap(QPixmap("../SFPackage/Smart-Fly_Logo3.jpg"));
        pLayoutLogo = new QHBoxLayout;
        pLayoutLogo->addWidget(pLabelSF_Logo);
        pNameLabel = new QLabel;
        pNameLabel->setText(QString("No Unit Loaded"));
        pNameLabel->setAlignment(Qt::AlignCenter);
        int PointSize = QApplication::font().pointSize();
        pNameLabel->setFont(QFont("Verdana", (PointSize*4)));
        pNameLabel->setScaledContents(true);

        pLayoutUnitName  = new QHBoxLayout;                                         
        pLayoutUnitName->addWidget(pNameLabel);                                     
                                                                                    
        pFileInfoLabel = new QLabel;                                                
                                                                                    
        pGroupInfoLeft   = new QGroupBox;                                           
        pGroupInfoLeft->setStyleSheet(                                              
            QLatin1String("QGroupBox{border: 2px solid rgb(127, 127, 127);"         
                          "       border-radius: 3px}"));                           
        pGroupInfoLeft->setTitle("Configuration File");                             
        pGroupInfoRight  = new QGroupBox;                                           
        pGroupInfoRight->setStyleSheet(                                             
            QLatin1String("QGroupBox{border: 2px solid rgb(127, 127, 127);"         
                          "       border-radius: 3px}"));                           
        pGroupInfoRight->setTitle("Attached Unit");                                 
        pLayoutInfoLeft = new QVBoxLayout;                                          
        pLayoutInfoLeft->addWidget(pFileInfoLabel);                                 
        pGroupInfoLeft->setLayout(pLayoutInfoLeft);                                 
        pLayoutInfoRight = new QVBoxLayout;                                         
        pGroupInfoRight->setLayout(pLayoutInfoRight);                               
        pLayoutInfoBase = new QHBoxLayout;                                          
        pLayoutInfoBase->addWidget(pGroupInfoLeft);                                 
        pLayoutInfoBase->addWidget(pGroupInfoRight);                                
                                                                                    
        pLayoutMainV = new QVBoxLayout;                                             
        pLayoutMainV->addLayout(pLayoutLogo);                                       
        pLayoutMainV->addLayout(pLayoutUnitName);                                   
        pLayoutMainV->addSpacing(12);                                               
        pLayoutMainV->addLayout(pLayoutInfoBase);                                   
        pLayoutMainV->addStretch();                                                 
                                                                                    
        pLayoutMainH = new QHBoxLayout;                                             
        pLayoutMainH->addLayout(pLayoutMainV);                                      
        pLayoutMainH->addStretch();                                                 
        setLayout(pLayoutMainH);                                                    
        

        }
        @

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

          Hi,

          Does it also happen if you remove the style sheet ?

          By the way, which version of windows are you running ?

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

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ambershark
            wrote on last edited by
            #5

            I have seen that behavior with bad style sheets before. Like SGaist said comment out the style sheet and see if that fixes it, then you need to tweak your style sheet to make it look right.

            I have had to play with stylesheets a lot to get them to look right with widgets. And usually I need separate sheets for each OS.

            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

            1 Reply Last reply
            0
            • R Offline
              R Offline
              RRRitchey
              wrote on last edited by
              #6

              Thanks for the suggestion. That helped. I am very new to this UI stuff, have written embedded code for 30 years but no UI. I would like a more defined boarder on the group box. Any suggestions on how to accomplish that without getting back in trouble? SGalst, I am running on XT until I finish this then moving all my stuff to Win7.

              !http://i58.tinypic.com/2ppe99u.jpg(No Style Sheet)!

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

                Look at the "Qt Style Sheet Examples" and search for "Customizing QGroupBox" You have there a good base to start with to customize your QGroupBox

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

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  RRRitchey
                  wrote on last edited by
                  #8

                  I have been for about the last 3 hours and it mostly gets worse, not better. Very frustrating. I have managed to get the label basically where I want it but it now completely ignores the boarder setting. The boarder is just the default boarder. If the style sheet was bad I get a notice on the console it cannot be parsed but I am not getting any notice that there is any problem with this. This is what I have in the code:
                  @
                  pGroupInfoLeft->setStyleSheet(
                  QLatin1String("QGroupBox{border: 2px solid rgb(127, 127, 127);"
                  " border-radius: 3px;}"));
                  pGroupInfoLeft->setStyleSheet(
                  QLatin1String("QGroupBox::title{subcontrol-origin: margin;"
                  " subcontrol-position: top center;}"));
                  @

                  Any thoughts on why the boarder specification is being ignored? Thanks,

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    ambershark
                    wrote on last edited by
                    #9

                    It's because you overwrote the stylesheet with the border with the new one. Calling setStyleSheet completely replaces the stylesheet so what you should do is combine those 2:

                    @
                    QString ss = "QGroupBox {"
                    "border: 2px solid rgb(127,127,17);"
                    "border-radius: 3px;"
                    "}"
                    "QGroupBox::title {"
                    "subcontrol-origin: margin;"
                    "subcontrol-position: top center;
                    "}";

                    pGroupInfoLeft->setStyleSheet(ss);
                    @

                    You can of course omit the QString and just put all that straight into the setStyleSheet call.

                    My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      RRRitchey
                      wrote on last edited by
                      #10

                      Thanks, I had just figured that out when I got your email. I naively thought that changing a style setting would just update that setting. I also read somewhere that when no styles are set the OS draws the items. When you start setting styles for an object then Qt starts drawing them. So that seems to be why just modifying the boarder width and color affects other items like the title placement. Also figured out I needed to specify a margin-top value to move the text up. Pretty much have the look I want. I had hoped to allow the user to modify the text font and size but that is looking like it will not work very well given the various style tweaks needed to get things to look a certain way.

                      1 Reply Last reply
                      0

                      • Login

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