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. QLayout is wasting space
Forum Updated to NodeBB v4.3 + New Features

QLayout is wasting space

Scheduled Pinned Locked Moved Unsolved General and Desktop
qlayoutqwidget
7 Posts 3 Posters 2.0k Views 2 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
    Ralf
    wrote on 9 Nov 2015, 16:45 last edited by Ralf 11 Oct 2015, 10:43
    #1

    I add Qwidgets dynamically

    for(int i = 0; i < value; i++)
    {
    QList<QWidget*> widgetList_i;
    //... widgetList_i.append(a lot of widgets)
    ui->verticalLayout->addWidget(widget_i);
    }

    during runtime to my app. As you can see here there is a lot of space wasted between those QWidgets. I am able to drag the border between the two dockWidgets and compress the lower layout like here

    But I do not want to do that manually. How can I start a layout already compressed?

    EDIT: In short, I expect two things:

    1. Start that lower dockWidget/layout compressed, with no space wasting.
    2. After starting is should be possible to increase its size
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 9 Nov 2015, 16:55 last edited by
      #2

      @Ralf said:
      try set widgets_i maximumheight to say 32 (for each)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 9 Nov 2015, 17:15 last edited by
        #3

        Hi,

        Your widgets are currently evenly spaced inside your layout. What you can do is add ui->verticalLayout->addStretch(1); after your loop. That will create a stretchable space that should push your widgets up as much as possible.

        Hope it helps

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

        R 1 Reply Last reply 9 Nov 2015, 17:53
        1
        • R Offline
          R Offline
          Ralf
          wrote on 9 Nov 2015, 17:39 last edited by Ralf 11 Sept 2015, 17:54
          #4

          @mrjj nice approach, but then I have wasted space again, see red area

          1 Reply Last reply
          0
          • S SGaist
            9 Nov 2015, 17:15

            Hi,

            Your widgets are currently evenly spaced inside your layout. What you can do is add ui->verticalLayout->addStretch(1); after your loop. That will create a stretchable space that should push your widgets up as much as possible.

            Hope it helps

            R Offline
            R Offline
            Ralf
            wrote on 9 Nov 2015, 17:53 last edited by
            #5

            @SGaist added! The beginning of that layout is nice. The end again space waisted

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 9 Nov 2015, 20:31 last edited by
              #6

              Are you expecting the layout contained in your "dock" widget to resize the widget itself ?

              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
                Ralf
                wrote on 10 Nov 2015, 09:07 last edited by
                #7

                I added
                ui->verticalLayout->parentWidget()->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Maximum);
                which organized the containing widgets perfectly.
                But that opened another problem, No I can not resize (move border between dockwidgets) between the Dockwidgets..

                1 Reply Last reply
                0

                3/7

                9 Nov 2015, 17:15

                • Login

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