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 not fit internal layout
Forum Updated to NodeBB v4.3 + New Features

QGroupBox not fit internal layout

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 5 Posters 2.0k Views 3 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by SGaist
    #2

    Hi,

    Which version of Qt ?
    On which version of Windows ?
    Can you please provide a minimal compilable example to reproduce this ?
    The snippet you provided does not include the dialog creation nor the buttons so this might hide something else regarding your issue.

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

    S 1 Reply Last reply
    0
    • S Offline
      S Offline
      SergeyK12
      wrote on last edited by
      #3

      This worked if size of QLabel is smaller.
      But i still can minimize window less than fixed size. Because of QGroupBox. And window same as on image above.

      1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Which version of Qt ?
        On which version of Windows ?
        Can you please provide a minimal compilable example to reproduce this ?
        The snippet you provided does not include the dialog creation nor the buttons so this might hide something else regarding your issue.

        S Offline
        S Offline
        SergeyK12
        wrote on last edited by
        #4

        @SGaist
        Latest Qt (6.7.3)
        Windows

        I prepare separate example (from code i mention in the post) and it is fully correct.
        The difference is that i use designer with my original question.

        I'm at a loss. Maybe sizes or policies...

        Thanks for your help.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SergeyK12
          wrote on last edited by
          #5

          Or maby because of QDialog i use

          S 1 Reply Last reply
          0
          • Axel SpoerlA Offline
            Axel SpoerlA Offline
            Axel Spoerl
            Moderators
            wrote on last edited by
            #6

            The dialog is too small to fit two fixed size labels (plus a group box overhead for each). That’s why the group boxes are both cropped. Increase the dialog size and the issue goes away :-)

            Software Engineer
            The Qt Company, Oslo

            S 1 Reply Last reply
            1
            • S SergeyK12

              Or maby because of QDialog i use

              S Offline
              S Offline
              SergeyK12
              wrote on last edited by
              #7

              @SergeyK12
              QDialog could adjust size to it content:
              f86d6b78-0774-4c41-a2e2-74cee69fd223-image.png

              But if i push this QLabel into a layout into QGroupBox
              a6f57f15-071e-4b90-a588-413d33b49770-image.png

              Its not ajust QGroubBox layout.

              But if i do the same withoun QDialog (test example with QMainWindow)
              e4f4abe1-20cf-4715-81cb-8e4fa101f3c8-image.png
              everything is fine

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SergeyK12
                wrote on last edited by
                #8

                If i call adjustSize
                476c79ed-4fdc-4229-ad2a-559992d5a6a1-image.png

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SergeyK12
                  wrote on last edited by SergeyK12
                  #9

                  QGroupBox is broken with QDialog.
                  I could (possably) avoid this by creating CustomWidget included QGroupBox.
                  But the problem exist.

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    As soon as the requested minimum size does not fit into the layout (as it seems in your example) the layout manager can't do anything.
                    This is working fine:

                    int main(int argc, char **argv)
                    {
                        QApplication a(argc, argv);
                        QWidget w;
                        auto vlay = new QVBoxLayout(&w);
                        for (int i = 0; i != 2; ++i) {
                            auto groupBox = new QGroupBox("GroupBox");
                            groupBox->setCheckable(true);
                            groupBox->setAlignment(Qt::AlignLeft);
                    
                            auto* lay = new QVBoxLayout;
                            auto* lab = new QLabel("Test");
                    
                            lab->setFixedSize(500, 200);
                            lay->addWidget(lab);
                    
                            groupBox->setLayout(lay);
                            groupBox->adjustSize();
                    
                            vlay->addWidget(groupBox);
                        }
                        w.show();
                        return app.exec();
                    }
                    

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    S 1 Reply Last reply
                    1
                    • Christian EhrlicherC Christian Ehrlicher

                      As soon as the requested minimum size does not fit into the layout (as it seems in your example) the layout manager can't do anything.
                      This is working fine:

                      int main(int argc, char **argv)
                      {
                          QApplication a(argc, argv);
                          QWidget w;
                          auto vlay = new QVBoxLayout(&w);
                          for (int i = 0; i != 2; ++i) {
                              auto groupBox = new QGroupBox("GroupBox");
                              groupBox->setCheckable(true);
                              groupBox->setAlignment(Qt::AlignLeft);
                      
                              auto* lay = new QVBoxLayout;
                              auto* lab = new QLabel("Test");
                      
                              lab->setFixedSize(500, 200);
                              lay->addWidget(lab);
                      
                              groupBox->setLayout(lay);
                              groupBox->adjustSize();
                      
                              vlay->addWidget(groupBox);
                          }
                          w.show();
                          return app.exec();
                      }
                      
                      S Offline
                      S Offline
                      SergeyK12
                      wrote on last edited by SergeyK12
                      #11

                      @Christian-Ehrlicher
                      As you mention, Its perfectly work without QDialog.
                      In my previous post third example (it work with any number of boxes)
                      Thats mean that requested minimum size inside QGroupBox fit without QDialog.

                      Why it doesn't with QDialog?

                      It also work with QDialog without Boxes (first imфge in previous post).

                      Christian EhrlicherC 1 Reply Last reply
                      0
                      • S SergeyK12

                        @Christian-Ehrlicher
                        As you mention, Its perfectly work without QDialog.
                        In my previous post third example (it work with any number of boxes)
                        Thats mean that requested minimum size inside QGroupBox fit without QDialog.

                        Why it doesn't with QDialog?

                        It also work with QDialog without Boxes (first imфge in previous post).

                        Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        @SergeyK12 said in QGroupBox not fit internal layout:

                        Why it doesn't with QDialog?

                        Because, as I wrote above, you did not set a minimum size on your QDialog but your QWidget or whatever so the layout constraints inside are greater than your minimum size.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        S 1 Reply Last reply
                        0
                        • Christian EhrlicherC Christian Ehrlicher

                          @SergeyK12 said in QGroupBox not fit internal layout:

                          Why it doesn't with QDialog?

                          Because, as I wrote above, you did not set a minimum size on your QDialog but your QWidget or whatever so the layout constraints inside are greater than your minimum size.

                          S Offline
                          S Offline
                          SergeyK12
                          wrote on last edited by SergeyK12
                          #13

                          @Christian-Ehrlicher
                          Sorry, i missunderstand.

                          I set sizes only for internal widgets.

                          Im not set minimum size in other working examples. So you didnt in yours.
                          (it calc size for any number of wigets without QGroupBox).

                          With QGroupBox there is additional layouts and thats the case.

                          I should set minimum size for QDialog?

                          Its some specific behaviour of QGroupBox or QDialog? (since its work with QMainWindow etc)

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SergeyK12
                            wrote on last edited by
                            #14

                            image.png
                            QGroupBox and its layout live their own lives. But in all working examples they fit each other.

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              SergeyK12
                              wrote on last edited by SergeyK12
                              #15

                              If size of internal widget not fixed by enything its ok, but seems like nothing.
                              Try to combine with scroll (it will be good enough if internal widget in QScrollWidget could be any size it should be).
                              But fixing internal leed to this post discussion.

                              But its perfect (as it should be) without GroupBox (i cant understand this)

                              8efcc77f-de2f-4944-b0b5-ddbe20137d6a-image.png

                              1 Reply Last reply
                              0
                              • Axel SpoerlA Offline
                                Axel SpoerlA Offline
                                Axel Spoerl
                                Moderators
                                wrote on last edited by
                                #16

                                A QGroupBox has some specific features, and so has a QDialog. They don't work together in your case, but hat doesn't constitute a bug.
                                The documentation of QDialog says directly at the beginning:

                                A dialog window is a top-level window mostly used for short-term tasks and brief communications with the user.

                                It seems the use case is neither short term, nor brief. If it's all about plugins, there's also no need for the power of QDialog. You could just add two push buttons to a simple QWidget at the bottom of a layout.

                                Without having researched it in Detail: A group box automatically has a Preferred size policy and it's a control type of its own.
                                E.g. the fusion style adds some space below the group box, which is accounted for in QGroupBox::minimumSizeHint(). That could be a reason.

                                @SergeyK12 said in QGroupBox not fit internal layout:

                                Try to combine with scroll (it will be good enough if internal widget in QScrollWidget could be any size it should be).

                                There is no such thing as a QScrollWidget. Do you mean a QScrollArea? If you do, have you tried it in combination with group boxes in a dialog?

                                Software Engineer
                                The Qt Company, Oslo

                                1 Reply Last reply
                                0
                                • Axel SpoerlA Axel Spoerl

                                  The dialog is too small to fit two fixed size labels (plus a group box overhead for each). That’s why the group boxes are both cropped. Increase the dialog size and the issue goes away :-)

                                  S Offline
                                  S Offline
                                  SimonSchroeder
                                  wrote on last edited by
                                  #17

                                  @Axel-Spoerl said in QGroupBox not fit internal layout:

                                  Increase the dialog size and the issue goes away :-)

                                  Isn't this what the outer layout is for?

                                  @SergeyK12 In the short snippet you have showed vlay is not set as the layout of your dialog before you call this->adjustSize(). However, there is always a slight problem with this: Anything to do with the layout calculations only works after the dialog is shown. So, adjustSize() might work if you call this->show() directly before.

                                  In general, you should rarely have a need to use fixed sizes. Everything should be handled by layouts. There might be a problem (I'm not entirely sure) that the fixed size does not communicate its behavior to the layout. The minimum size and size hint might tell the layout something entirely different. I personally would use setMinimumSize() instead of setFixedSize(). If you want to avoid for the label to be larger than the minimum size, you should set the size policy (both horizontal and vertical size policy) to QSizePolicy::Fixed. If the user still tries to make the dialog larger, something needs to be resized. You can add a QSpacerItem with zero height/width some place in your layouts to account for that (for box layouts you can use addStretch(0) directly).

                                  1 Reply Last reply
                                  0
                                  • S SergeyK12 has marked this topic as solved on

                                  • Login

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