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. Fix the position of a layout, which is present on top of another layout, at the bottom of the screen.
Forum Update on Monday, May 27th 2025

Fix the position of a layout, which is present on top of another layout, at the bottom of the screen.

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 316 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.
  • S Offline
    S Offline
    shreya_agrawal
    wrote on last edited by
    #1

    I have my main layout as a QVBoxLayout. In that, I am adding a grid layout and a QHBoxLayout. In the QHBoxLayout, I have a next button and a previous button. When I click on next button, the size of the grid decreases (as number of elements in the grid decreases). Due to this, these buttons shift upwards. But I want these buttons to not move in the vertical direction. They should have a fixed position. How to do this, without using a spacer?

    JonBJ 1 Reply Last reply
    0
    • S shreya_agrawal

      I have my main layout as a QVBoxLayout. In that, I am adding a grid layout and a QHBoxLayout. In the QHBoxLayout, I have a next button and a previous button. When I click on next button, the size of the grid decreases (as number of elements in the grid decreases). Due to this, these buttons shift upwards. But I want these buttons to not move in the vertical direction. They should have a fixed position. How to do this, without using a spacer?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @shreya_agrawal
      If I understand right, on a QVBoxLayout you have a QGridLayout above a QHBoxLayout. If you want the QHBoxLayout to stay at the bottom of the QVBoxLayout regardless of what is above it (QGridLayout) then you are indeed supposed to use vertical QSpacerItem above it to "push" it to the bottom. So not sure why you don't what that or what the alternative would be.

      S 1 Reply Last reply
      0
      • JonBJ JonB

        @shreya_agrawal
        If I understand right, on a QVBoxLayout you have a QGridLayout above a QHBoxLayout. If you want the QHBoxLayout to stay at the bottom of the QVBoxLayout regardless of what is above it (QGridLayout) then you are indeed supposed to use vertical QSpacerItem above it to "push" it to the bottom. So not sure why you don't what that or what the alternative would be.

        S Offline
        S Offline
        shreya_agrawal
        wrote on last edited by
        #3

        @JonB
        Thank you for your reply !
        I actually implemented the QSpacerItem, but I have been told that it could also be done in another way, by using some property of QVBoxLayout. So, I just wanted to confirm if any such property exists.

        JonBJ 1 Reply Last reply
        0
        • S shreya_agrawal

          @JonB
          Thank you for your reply !
          I actually implemented the QSpacerItem, but I have been told that it could also be done in another way, by using some property of QVBoxLayout. So, I just wanted to confirm if any such property exists.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @shreya_agrawal
          I find layout-ing to be a dark art!

          Most likely you are thinking of: when adding your widget(s) to the layout have a look at void QBoxLayout::addWidget(QWidget *widget, int stretch = 0, Qt::Alignment alignment = Qt::Alignment()). The optional stretch parameter allows you pass, say, 2 for one widget and 1 for another. Then it would allocate two-thirds of the available space to the first one and one-third to the second. Which won't do you. You could try passing 1 for the top one and 0 for the bottom one, but I don't think that allocates all space for the former and minimal for the latter, though you could test. And/or you could try passing Qt::AlignBottom for alignment on the bottom one, again not sure if that does what you want. Try them. (I believe you can set necessary properties for these from Qt Designer if not doing it in code.) If they work you have penetrated a portion of the dark art :)

          My recollection is being told that for your case putting in QSpacerItems is the way to do it.

          S 1 Reply Last reply
          0
          • JonBJ JonB

            @shreya_agrawal
            I find layout-ing to be a dark art!

            Most likely you are thinking of: when adding your widget(s) to the layout have a look at void QBoxLayout::addWidget(QWidget *widget, int stretch = 0, Qt::Alignment alignment = Qt::Alignment()). The optional stretch parameter allows you pass, say, 2 for one widget and 1 for another. Then it would allocate two-thirds of the available space to the first one and one-third to the second. Which won't do you. You could try passing 1 for the top one and 0 for the bottom one, but I don't think that allocates all space for the former and minimal for the latter, though you could test. And/or you could try passing Qt::AlignBottom for alignment on the bottom one, again not sure if that does what you want. Try them. (I believe you can set necessary properties for these from Qt Designer if not doing it in code.) If they work you have penetrated a portion of the dark art :)

            My recollection is being told that for your case putting in QSpacerItems is the way to do it.

            S Offline
            S Offline
            shreya_agrawal
            wrote on last edited by
            #5

            @JonB
            Thank you for your time !
            I tried using the alternative solutions you mentioned, but none of them is giving the desired results. I guess I will stick to using a QSpacerItem.

            1 Reply Last reply
            1
            • S shreya_agrawal 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