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. [SOLVED] Resizing Custom Widgets in a Layout Leaves Empty Space Between Widgets
QtWS25 Last Chance

[SOLVED] Resizing Custom Widgets in a Layout Leaves Empty Space Between Widgets

Scheduled Pinned Locked Moved General and Desktop
layoutqt 5.4.1qt5.4customc++widgetqt 5.4widgetsapplicationdesktop
20 Posts 4 Posters 15.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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #11

    If you manage all your pods like the widgets inside them, then you need to do all the mathematics to ensure they are placed and spaced correctly. That's why I suggest using a layout manager inside them and also to handle them

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

    Bolt2strikeB 1 Reply Last reply
    0
    • SGaistS SGaist

      If you manage all your pods like the widgets inside them, then you need to do all the mathematics to ensure they are placed and spaced correctly. That's why I suggest using a layout manager inside them and also to handle them

      Bolt2strikeB Offline
      Bolt2strikeB Offline
      Bolt2strike
      wrote on last edited by Bolt2strike
      #12

      @SGaist @Chris-Kawa ..... Still not seeing your point, and yes now that I think about it it probably would have been better to have another layout as a member of Pod. But, as for managing placing and spacing, I don't get it, I just construct the object in a QList<Pod *> named PodList and subsequently place it into the layout, then they need not be moved again. I'm not sure if I've mentioned this previously but, the issue with the empty space comes in when I resize TextLabel, ImageLabel and their scroll areas.

          QList<Pod*> PodList;
          for (int p=0; p!=NumPods; p++)
          {
              PodList.insert(p,new Pod(0,0,400,150,this));
              MainLayout->insertWidget(p,PodList.at(p));
          }
      

      *MainLayout is the layout in the highest level scroll area

      Here I'll also include a picture to provide additional context to my issue
      ""

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

        Since you don't use a layout manager, you also need to take into account the position of your widgets when you resize

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

        Bolt2strikeB 1 Reply Last reply
        0
        • SGaistS SGaist

          Since you don't use a layout manager, you also need to take into account the position of your widgets when you resize

          Bolt2strikeB Offline
          Bolt2strikeB Offline
          Bolt2strike
          wrote on last edited by
          #14

          @SGaist Okay. But, if I've adjusted the size of the widgets inside the v box layout, shouldn't it resize to fit its children (OR is there a fixed space within the layout that I can position Pods in)? As evidently it doesn't, how can I create this behavior? And yes, I've tried setting size policy to fixed size.

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

            If the children of your widgets are not themselves handled by a layout manager, then no, they won't do anything automatically

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

            Bolt2strikeB 1 Reply Last reply
            0
            • SGaistS SGaist

              If the children of your widgets are not themselves handled by a layout manager, then no, they won't do anything automatically

              Bolt2strikeB Offline
              Bolt2strikeB Offline
              Bolt2strike
              wrote on last edited by
              #16

              @SGaist What? If a widget and all its children in a position above that of another widget were to uniformly decrease in size so that they take up less vertical space expanding downwards but maintain the same position of being in the top left, just like why? Why would this empty space exist the widgets have all decreased in size meaning that they have retracted from their position leaving space which I would have assumed would be removed so that the widgets in the next index position underneath could shift upwards. In other terms, if the size decreases as to retract from a position then shouldn't the layout adjust its allocated space for this widget? I've never had a problem with this before... And one last thing, as an answer to your statement, could I just apply a newly constructed layout to the widgets without setting anything and it would work?

              I'm sorry if I do sound a bit rude... I appreciate the help you and others on this form willingly provide, even if I am being difficult.

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

                Widgets in a layout manager are evenly distributed unless you modify their stretch factor (by default 0 IIRC). In the case of a vertical layout, if you add a stretch with a higher value at the last position you should have all your widgets pushed against one another to the top.

                QVBoxLayout *layout = new QVBoxLayout(this);
                layout->addWidget(widget1);
                layout->addWidget(widget2);
                etc.
                layout->addStretch(1);
                

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

                Bolt2strikeB 1 Reply Last reply
                0
                • SGaistS SGaist

                  Widgets in a layout manager are evenly distributed unless you modify their stretch factor (by default 0 IIRC). In the case of a vertical layout, if you add a stretch with a higher value at the last position you should have all your widgets pushed against one another to the top.

                  QVBoxLayout *layout = new QVBoxLayout(this);
                  layout->addWidget(widget1);
                  layout->addWidget(widget2);
                  etc.
                  layout->addStretch(1);
                  
                  Bolt2strikeB Offline
                  Bolt2strikeB Offline
                  Bolt2strike
                  wrote on last edited by Bolt2strike
                  #18
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #19

                    Good !

                    However, I'm not sure I'm following you on that one. Where did you put that resize ?

                    If you can't from the Topic Tools menu, then just edit the thread title and prepend [solved]

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

                    Bolt2strikeB 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Good !

                      However, I'm not sure I'm following you on that one. Where did you put that resize ?

                      If you can't from the Topic Tools menu, then just edit the thread title and prepend [solved]

                      Bolt2strikeB Offline
                      Bolt2strikeB Offline
                      Bolt2strike
                      wrote on last edited by
                      #20
                      This post is deleted!
                      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