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. Remove stretch in QVBoxLayout ?
Forum Updated to NodeBB v4.3 + New Features

Remove stretch in QVBoxLayout ?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 8.7k 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.
  • T Offline
    T Offline
    Tyskie
    wrote on last edited by Tyskie
    #1

    Hello,
    I have a QVBoxLayout with a QWidget added as central widget of my QMainWindow, with some QLabel in that QWidget. When I enlarge the QMainWindow in height, some stretch thingies can be seen between QLabel. I would like the QLabel to stick to the top and not have stretching between them when the height is bigger than their total height, is that possible?
    (see picture)
    Thanks !

    0_1565194407514_oops.png

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Add a stretch at the end of the layout:

      yourVBoxLayout->addStretch();
      
      1 Reply Last reply
      3
      • T Offline
        T Offline
        Tyskie
        wrote on last edited by Tyskie
        #3

        Thanks @Chris-Kawa, the issue with this is that when I add other QLabel dynamically throu a buttonit adds it after the stretch. see picture:

        0_1565202410462_oops2.png

        Actually I want to have the newest QLabel added at the top of the existing ones, then it would make sense to have the stretch at the bottom, like that, but I am not sure how I can add new widget at the top of other with QVBoxLayout, yet :D

        1 Reply Last reply
        0
        • T Offline
          T Offline
          Tyskie
          wrote on last edited by
          #4

          Wow cool that actually made it:

          [...]
          layout.addStretch()
          layout.setDirection(QBoxLayout.BottomToTop)
          //then add Widget
          [...]
          

          Adding widget later adds them at the top, and the stretch stays at bottom!

          Thanks :P

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

            Hi,

            Rather than adding widgets, use insert and set the position to one before the last.

            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
            • T Offline
              T Offline
              Tyskie
              wrote on last edited by Tyskie
              #6

              Hi, @SGaist isnt what setDirection() and BottomToTop are actually doing?

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

                Our posts crossed each other :-)

                It's another possibility yes.

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

                T 1 Reply Last reply
                0
                • SGaistS SGaist

                  Our posts crossed each other :-)

                  It's another possibility yes.

                  T Offline
                  T Offline
                  Tyskie
                  wrote on last edited by
                  #8

                  hehe thanks !

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

                    you can create a layout and at the start add a stretch with layout.addstretch()
                    then instert the widget at position count() - 1, ie layout.insertwidget(layout.count()-1, widget, *args, **kwargs)

                    1 Reply Last reply
                    1

                    • Login

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