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. Can't get my widget to auto-resize...

Can't get my widget to auto-resize...

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 5 Posters 29.0k 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.
  • M Offline
    M Offline
    mzimmers
    wrote on 5 Oct 2017, 18:25 last edited by
    #1

    ...my app has a QPlainTextBox in a QHBoxLayout (in a QWidget). I'd like it to grow vertically with the Widget.

    I've read the Layout Management page, and I don't see what I'm missing -- vertical policy is "Expanding," and maximum size is arbitrarily large. Any suggestions what to look for? Thanks.

    ? 1 Reply Last reply 5 Oct 2017, 18:44
    0
    • B Offline
      B Offline
      btse
      wrote on 5 Oct 2017, 18:34 last edited by
      #2

      Can you post the relevant code?

      1 Reply Last reply
      0
      • M mzimmers
        5 Oct 2017, 18:25

        ...my app has a QPlainTextBox in a QHBoxLayout (in a QWidget). I'd like it to grow vertically with the Widget.

        I've read the Layout Management page, and I don't see what I'm missing -- vertical policy is "Expanding," and maximum size is arbitrarily large. Any suggestions what to look for? Thanks.

        ? Offline
        ? Offline
        A Former User
        wrote on 5 Oct 2017, 18:44 last edited by
        #3

        @mzimmers Hi! Here's a minimal example:

        #include <QApplication>
        #include <QWidget>
        #include <QHBoxLayout>
        #include <QPlainTextEdit>
        
        int main(int argc, char *argv[])
        {
            QApplication a(argc, argv);
        
            QWidget widget; // main widget; our window
            auto layout = new QHBoxLayout(&widget); // "layout" it not a QWidget itself, it only manages QWidgets
            widget.setLayout(layout); // set "layout" as the layout manager for "widget"
            auto textEdit = new QPlainTextEdit(&widget); // "textEdit" has "widget" as its parent, but it's not managed yet
            layout->addWidget(textEdit); // tell "layout" to manage "textEdit"
            widget.show(); 
        
            return a.exec();
        }
        
        B 1 Reply Last reply 5 Oct 2017, 19:02
        0
        • ? A Former User
          5 Oct 2017, 18:44

          @mzimmers Hi! Here's a minimal example:

          #include <QApplication>
          #include <QWidget>
          #include <QHBoxLayout>
          #include <QPlainTextEdit>
          
          int main(int argc, char *argv[])
          {
              QApplication a(argc, argv);
          
              QWidget widget; // main widget; our window
              auto layout = new QHBoxLayout(&widget); // "layout" it not a QWidget itself, it only manages QWidgets
              widget.setLayout(layout); // set "layout" as the layout manager for "widget"
              auto textEdit = new QPlainTextEdit(&widget); // "textEdit" has "widget" as its parent, but it's not managed yet
              layout->addWidget(textEdit); // tell "layout" to manage "textEdit"
              widget.show(); 
          
              return a.exec();
          }
          
          B Offline
          B Offline
          btse
          wrote on 5 Oct 2017, 19:02 last edited by
          #4

          @Wieland I have tested your code snippet, and it resizes as expected. What version of Qt and OS are you on?

          ? 1 Reply Last reply 5 Oct 2017, 19:06
          0
          • B btse
            5 Oct 2017, 19:02

            @Wieland I have tested your code snippet, and it resizes as expected. What version of Qt and OS are you on?

            ? Offline
            ? Offline
            A Former User
            wrote on 5 Oct 2017, 19:06 last edited by A Former User 10 May 2017, 19:08
            #5

            @btse I know the code works, I've tested it. @mzimmers is the OP ;-)

            M 1 Reply Last reply 5 Oct 2017, 19:42
            0
            • ? A Former User
              5 Oct 2017, 19:06

              @btse I know the code works, I've tested it. @mzimmers is the OP ;-)

              M Offline
              M Offline
              mzimmers
              wrote on 5 Oct 2017, 19:42 last edited by
              #6

              @Wieland thanks for the example. I used Designer to build mine. The attributes all look the same as yours...any ideas?0_1507232518005_textbox.PNG

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 5 Oct 2017, 19:48 last edited by
                #7

                Hi,

                Are you sure the internal widgets are put in a layout that was applied to the edited widget ?

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

                M 1 Reply Last reply 5 Oct 2017, 19:50
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 5 Oct 2017, 19:49 last edited by
                  #8

                  @Wieland: no need to call setLayout if you passed the widget as parent at layout creation time it will be assigned automatically..

                  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
                  1
                  • S SGaist
                    5 Oct 2017, 19:48

                    Hi,

                    Are you sure the internal widgets are put in a layout that was applied to the edited widget ?

                    M Offline
                    M Offline
                    mzimmers
                    wrote on 5 Oct 2017, 19:50 last edited by
                    #9

                    @SGaist I believe so. All my widgets were created in Designer (no programmatic stuff). Here's the structure:
                    0_1507233048765_resize.PNG

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 5 Oct 2017, 19:58 last edited by
                      #10

                      It looks like groupBoxSecurity and groupBoxUserPwd are not in a layout.

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

                      M 1 Reply Last reply 5 Oct 2017, 20:00
                      2
                      • S SGaist
                        5 Oct 2017, 19:58

                        It looks like groupBoxSecurity and groupBoxUserPwd are not in a layout.

                        M Offline
                        M Offline
                        mzimmers
                        wrote on 5 Oct 2017, 20:00 last edited by
                        #11

                        @SGaist you're right; they aren't.

                        So, so I infer correctly that in order for resizing to occur, all widgets must be in a layout?

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 5 Oct 2017, 20:04 last edited by
                          #12

                          If you want that everything be resized automatically, then yes. Otherwise you would need to re-implemt the resize event and then do all the sizing by hand.

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

                          M 1 Reply Last reply 5 Oct 2017, 20:07
                          0
                          • S SGaist
                            5 Oct 2017, 20:04

                            If you want that everything be resized automatically, then yes. Otherwise you would need to re-implemt the resize event and then do all the sizing by hand.

                            M Offline
                            M Offline
                            mzimmers
                            wrote on 5 Oct 2017, 20:07 last edited by
                            #13

                            @SGaist OK, but I don't want everything to resize; just a few items (really, just the QPlainTextEdit widget).

                            1 Reply Last reply
                            0
                            • ? Offline
                              ? Offline
                              A Former User
                              wrote on 5 Oct 2017, 20:11 last edited by
                              #14

                              I bet you already know this:

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on 5 Oct 2017, 20:13 last edited by
                                #15

                                That should be achievable, Try playing with the stretch factor.

                                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
                                • M Offline
                                  M Offline
                                  mzimmers
                                  wrote on 5 Oct 2017, 20:30 last edited by
                                  #16

                                  I'll do some more experimentation. In general, is it better to build nested layouts from the outside in, or from the inside out?

                                  This app I'm writing appears as though it's going to need several layouts to present correctly.

                                  1 Reply Last reply
                                  0
                                  • M Offline
                                    M Offline
                                    mzimmers
                                    wrote on 6 Oct 2017, 19:39 last edited by
                                    #17

                                    OK, I'm obviously doing something wrong. Various experiments didn't work, so I put a (single) layout around every child widget in my display. Still no resizing. What am I overlooking?

                                    kshegunovK 1 Reply Last reply 6 Oct 2017, 19:44
                                    0
                                    • M mzimmers
                                      6 Oct 2017, 19:39

                                      OK, I'm obviously doing something wrong. Various experiments didn't work, so I put a (single) layout around every child widget in my display. Still no resizing. What am I overlooking?

                                      kshegunovK Offline
                                      kshegunovK Offline
                                      kshegunov
                                      Moderators
                                      wrote on 6 Oct 2017, 19:44 last edited by
                                      #18

                                      Take a screenshot (and make sure the object tree on the right is visible) so we can see what's going on.

                                      Read and abide by the Qt Code of Conduct

                                      1 Reply Last reply
                                      0
                                      • M Offline
                                        M Offline
                                        mzimmers
                                        wrote on 6 Oct 2017, 20:05 last edited by
                                        #19

                                        OK, I just got another data point, though I'm not sure what it means. So, this is my UI without any layouts applied:
                                        0_1507320128864_no_layout.PNG
                                        This does not do any resizing, nor would I expect it to.

                                        This is my UI with a grid layout applied to all child objects:
                                        0_1507320164793_child_layout.PNG

                                        This does not do any resizing; I thought that it would.

                                        This (the new data point) is with a grid applied to the main widget itself (oddly doesn't show up in the tree):
                                        0_1507320239217_all_layout.PNG

                                        This does resize.

                                        So, in short...I have no clue at all what I'm doing here. And I haven't even touched on the topic that the layouts are screwing up my UI. (This I presume can be fixed by nested layouts?)

                                        Thanks...

                                        kshegunovK 1 Reply Last reply 6 Oct 2017, 20:25
                                        0
                                        • M mzimmers
                                          6 Oct 2017, 20:05

                                          OK, I just got another data point, though I'm not sure what it means. So, this is my UI without any layouts applied:
                                          0_1507320128864_no_layout.PNG
                                          This does not do any resizing, nor would I expect it to.

                                          This is my UI with a grid layout applied to all child objects:
                                          0_1507320164793_child_layout.PNG

                                          This does not do any resizing; I thought that it would.

                                          This (the new data point) is with a grid applied to the main widget itself (oddly doesn't show up in the tree):
                                          0_1507320239217_all_layout.PNG

                                          This does resize.

                                          So, in short...I have no clue at all what I'm doing here. And I haven't even touched on the topic that the layouts are screwing up my UI. (This I presume can be fixed by nested layouts?)

                                          Thanks...

                                          kshegunovK Offline
                                          kshegunovK Offline
                                          kshegunov
                                          Moderators
                                          wrote on 6 Oct 2017, 20:25 last edited by kshegunov 10 Jun 2017, 20:34
                                          #20

                                          The last one looks good (almost no problems). You have to set layouts to your group boxes too and everything will be resizing. Also bear in mind you don't really need a grid layout for the top widget, vertical one (with 2 items) should do just fine.

                                          Edit.
                                          Actually I took a closer look. I'd put the two groups in a nested horizontal layout, the dropdown with buttons in a vertical one. The vertical one and the text area in a horizontal one and set the root widget's layout to vertical.

                                          You can judge if there's a layout attached to the widget by looking at the object tree - the red crossed circle means there's no layout. Otherwise the assigned layout is shown as an icon. The child objects you see in the tree will be ordered according to the set layout. In practice using a nested layout isn't very often needed, only occasionally.

                                          Read and abide by the Qt Code of Conduct

                                          M 1 Reply Last reply 6 Oct 2017, 20:50
                                          1

                                          3/22

                                          5 Oct 2017, 18:44

                                          topic:navigator.unread, 19
                                          • Login

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