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. set qhboxlayout to the bottom of the widget when i resize the window
Qt 6.11 is out! See what's new in the release blog

set qhboxlayout to the bottom of the widget when i resize the window

Scheduled Pinned Locked Moved Solved General and Desktop
qt6.6c++
7 Posts 4 Posters 1.7k Views 1 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.
  • A Offline
    A Offline
    a_coder
    wrote on last edited by a_coder
    #1

    i have a ui like thise9cf4eea-6b89-4509-ad76-27f41ffc43a2-image.png
    xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>MainWindow</class>
     <widget class="QMainWindow" name="MainWindow">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>600</width>
        <height>400</height>
       </rect>
      </property>
      <property name="minimumSize">
       <size>
        <width>600</width>
        <height>400</height>
       </size>
      </property>
      <property name="windowTitle">
       <string>MainWindow</string>
      </property>
      <widget class="QWidget" name="centralwidget">
       <property name="sizePolicy">
        <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
         <horstretch>1</horstretch>
         <verstretch>1</verstretch>
        </sizepolicy>
       </property>
       <widget class="QWidget" name="verticalLayoutWidget">
        <property name="geometry">
         <rect>
          <x>0</x>
          <y>350</y>
          <width>602</width>
          <height>51</height>
         </rect>
        </property>
        <layout class="QVBoxLayout" name="verticalLayout">
         <item>
          <layout class="QHBoxLayout" name="horizontalLayout">
           <item>
            <widget class="QPushButton" name="pushButton">
             <property name="minimumSize">
              <size>
               <width>40</width>
               <height>40</height>
              </size>
             </property>
             <property name="maximumSize">
              <size>
               <width>40</width>
               <height>40</height>
              </size>
             </property>
             <property name="text">
              <string><-</string>
             </property>
            </widget>
           </item>
           <item>
            <widget class="QStackedWidget" name="stackedWidget">
             <property name="minimumSize">
              <size>
               <width>420</width>
               <height>40</height>
              </size>
             </property>
             <property name="maximumSize">
              <size>
               <width>16777215</width>
               <height>40</height>
              </size>
             </property>
             <property name="currentIndex">
              <number>0</number>
             </property>
             <widget class="QWidget" name="page"/>
             <widget class="QWidget" name="page_2"/>
            </widget>
           </item>
           <item>
            <widget class="QLabel" name="count">
             <property name="minimumSize">
              <size>
               <width>50</width>
               <height>40</height>
              </size>
             </property>
             <property name="maximumSize">
              <size>
               <width>70</width>
               <height>40</height>
              </size>
             </property>
             <property name="text">
              <string>time</string>
             </property>
            </widget>
           </item>
           <item>
            <widget class="QLabel" name="time">
             <property name="minimumSize">
              <size>
               <width>70</width>
               <height>40</height>
              </size>
             </property>
             <property name="maximumSize">
              <size>
               <width>70</width>
               <height>40</height>
              </size>
             </property>
             <property name="text">
              <string>time1</string>
             </property>
            </widget>
           </item>
          </layout>
         </item>
        </layout>
       </widget>
      </widget>
     </widget>
     <resources/>
     <connections/>
    </ui>
    

    But how do I make qhboxlayout always stay at the bottom and stick to both sides of the gui even when I change the window size?

    Pl45m4P JonBJ 2 Replies Last reply
    0
    • A a_coder

      i have a ui like thise9cf4eea-6b89-4509-ad76-27f41ffc43a2-image.png
      xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <ui version="4.0">
       <class>MainWindow</class>
       <widget class="QMainWindow" name="MainWindow">
        <property name="geometry">
         <rect>
          <x>0</x>
          <y>0</y>
          <width>600</width>
          <height>400</height>
         </rect>
        </property>
        <property name="minimumSize">
         <size>
          <width>600</width>
          <height>400</height>
         </size>
        </property>
        <property name="windowTitle">
         <string>MainWindow</string>
        </property>
        <widget class="QWidget" name="centralwidget">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
           <horstretch>1</horstretch>
           <verstretch>1</verstretch>
          </sizepolicy>
         </property>
         <widget class="QWidget" name="verticalLayoutWidget">
          <property name="geometry">
           <rect>
            <x>0</x>
            <y>350</y>
            <width>602</width>
            <height>51</height>
           </rect>
          </property>
          <layout class="QVBoxLayout" name="verticalLayout">
           <item>
            <layout class="QHBoxLayout" name="horizontalLayout">
             <item>
              <widget class="QPushButton" name="pushButton">
               <property name="minimumSize">
                <size>
                 <width>40</width>
                 <height>40</height>
                </size>
               </property>
               <property name="maximumSize">
                <size>
                 <width>40</width>
                 <height>40</height>
                </size>
               </property>
               <property name="text">
                <string><-</string>
               </property>
              </widget>
             </item>
             <item>
              <widget class="QStackedWidget" name="stackedWidget">
               <property name="minimumSize">
                <size>
                 <width>420</width>
                 <height>40</height>
                </size>
               </property>
               <property name="maximumSize">
                <size>
                 <width>16777215</width>
                 <height>40</height>
                </size>
               </property>
               <property name="currentIndex">
                <number>0</number>
               </property>
               <widget class="QWidget" name="page"/>
               <widget class="QWidget" name="page_2"/>
              </widget>
             </item>
             <item>
              <widget class="QLabel" name="count">
               <property name="minimumSize">
                <size>
                 <width>50</width>
                 <height>40</height>
                </size>
               </property>
               <property name="maximumSize">
                <size>
                 <width>70</width>
                 <height>40</height>
                </size>
               </property>
               <property name="text">
                <string>time</string>
               </property>
              </widget>
             </item>
             <item>
              <widget class="QLabel" name="time">
               <property name="minimumSize">
                <size>
                 <width>70</width>
                 <height>40</height>
                </size>
               </property>
               <property name="maximumSize">
                <size>
                 <width>70</width>
                 <height>40</height>
                </size>
               </property>
               <property name="text">
                <string>time1</string>
               </property>
              </widget>
             </item>
            </layout>
           </item>
          </layout>
         </widget>
        </widget>
       </widget>
       <resources/>
       <connections/>
      </ui>
      

      But how do I make qhboxlayout always stay at the bottom and stick to both sides of the gui even when I change the window size?

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

      @a_coder
      Hi. I believe you will find your design is not "correct", and I would start by getting that right.

      In the Object Inspector at the right you can see your centralWidget has a "red no-entry" sign on it. That tells you it is a widget which needs to have a layout but lacks one. I don't believe there is any (common) situation in which you want to leave it like that.

      You have placed a new widget, which has a vertical layout, directly onto centralWidget. Instead you should have selected centralWidget, right-clicked on it, and used the bottom item on the menu there to set a vertical layout on the centralWidget. There should be no "no-entry" sign then. (Note that, irritatingly, Designer only allows you set a widget's layout after you have added at least one item onto it, not when it's empty.) You can then place your horizontalLayout onto that.

      It's fiddly to remove content and then put it elsewhere in Designer, it's probably easier for you to delete/start over.

      I see others have posted while I have been composing this. (Though I do not see any need for a QGridLayout here.) Hopefully my post will help you sort that part out.

      A 2 Replies Last reply
      1
      • Ronel_qtmasterR Offline
        Ronel_qtmasterR Offline
        Ronel_qtmaster
        wrote on last edited by
        #2

        @a_coder it is simple:
        1 use gridlayout as the main layout
        2 in the grid layout, you can add an horizontal layout at the bottom then include your widgets
        3 to keep them at the bottom, add a vertical spacer in the grid layout at the top

        1 Reply Last reply
        0
        • A a_coder

          i have a ui like thise9cf4eea-6b89-4509-ad76-27f41ffc43a2-image.png
          xml:

          <?xml version="1.0" encoding="UTF-8"?>
          <ui version="4.0">
           <class>MainWindow</class>
           <widget class="QMainWindow" name="MainWindow">
            <property name="geometry">
             <rect>
              <x>0</x>
              <y>0</y>
              <width>600</width>
              <height>400</height>
             </rect>
            </property>
            <property name="minimumSize">
             <size>
              <width>600</width>
              <height>400</height>
             </size>
            </property>
            <property name="windowTitle">
             <string>MainWindow</string>
            </property>
            <widget class="QWidget" name="centralwidget">
             <property name="sizePolicy">
              <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
               <horstretch>1</horstretch>
               <verstretch>1</verstretch>
              </sizepolicy>
             </property>
             <widget class="QWidget" name="verticalLayoutWidget">
              <property name="geometry">
               <rect>
                <x>0</x>
                <y>350</y>
                <width>602</width>
                <height>51</height>
               </rect>
              </property>
              <layout class="QVBoxLayout" name="verticalLayout">
               <item>
                <layout class="QHBoxLayout" name="horizontalLayout">
                 <item>
                  <widget class="QPushButton" name="pushButton">
                   <property name="minimumSize">
                    <size>
                     <width>40</width>
                     <height>40</height>
                    </size>
                   </property>
                   <property name="maximumSize">
                    <size>
                     <width>40</width>
                     <height>40</height>
                    </size>
                   </property>
                   <property name="text">
                    <string><-</string>
                   </property>
                  </widget>
                 </item>
                 <item>
                  <widget class="QStackedWidget" name="stackedWidget">
                   <property name="minimumSize">
                    <size>
                     <width>420</width>
                     <height>40</height>
                    </size>
                   </property>
                   <property name="maximumSize">
                    <size>
                     <width>16777215</width>
                     <height>40</height>
                    </size>
                   </property>
                   <property name="currentIndex">
                    <number>0</number>
                   </property>
                   <widget class="QWidget" name="page"/>
                   <widget class="QWidget" name="page_2"/>
                  </widget>
                 </item>
                 <item>
                  <widget class="QLabel" name="count">
                   <property name="minimumSize">
                    <size>
                     <width>50</width>
                     <height>40</height>
                    </size>
                   </property>
                   <property name="maximumSize">
                    <size>
                     <width>70</width>
                     <height>40</height>
                    </size>
                   </property>
                   <property name="text">
                    <string>time</string>
                   </property>
                  </widget>
                 </item>
                 <item>
                  <widget class="QLabel" name="time">
                   <property name="minimumSize">
                    <size>
                     <width>70</width>
                     <height>40</height>
                    </size>
                   </property>
                   <property name="maximumSize">
                    <size>
                     <width>70</width>
                     <height>40</height>
                    </size>
                   </property>
                   <property name="text">
                    <string>time1</string>
                   </property>
                  </widget>
                 </item>
                </layout>
               </item>
              </layout>
             </widget>
            </widget>
           </widget>
           <resources/>
           <connections/>
          </ui>
          

          But how do I make qhboxlayout always stay at the bottom and stick to both sides of the gui even when I change the window size?

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by
          #3

          @a_coder said in set qhboxlayout to the bottom of the widget when i resize the window:

          But how do I make qhboxlayout always stay at the bottom and stick to both sides of the gui even when I change the window size?

          Don't add a new verticalLayout below centralWidget, but add a verticalLayout to your centralWidget.
          (you can tell from the red crossed circle sign next from centralWidget in Object Inspector)
          There are dozens of topics here on the forum on how to do it.

          Then, you need to a vertical spacer to push your bottom layout item in the QVBoxLayout (which is your QHBoxLayout and its content) down.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          2
          • A a_coder

            i have a ui like thise9cf4eea-6b89-4509-ad76-27f41ffc43a2-image.png
            xml:

            <?xml version="1.0" encoding="UTF-8"?>
            <ui version="4.0">
             <class>MainWindow</class>
             <widget class="QMainWindow" name="MainWindow">
              <property name="geometry">
               <rect>
                <x>0</x>
                <y>0</y>
                <width>600</width>
                <height>400</height>
               </rect>
              </property>
              <property name="minimumSize">
               <size>
                <width>600</width>
                <height>400</height>
               </size>
              </property>
              <property name="windowTitle">
               <string>MainWindow</string>
              </property>
              <widget class="QWidget" name="centralwidget">
               <property name="sizePolicy">
                <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
                 <horstretch>1</horstretch>
                 <verstretch>1</verstretch>
                </sizepolicy>
               </property>
               <widget class="QWidget" name="verticalLayoutWidget">
                <property name="geometry">
                 <rect>
                  <x>0</x>
                  <y>350</y>
                  <width>602</width>
                  <height>51</height>
                 </rect>
                </property>
                <layout class="QVBoxLayout" name="verticalLayout">
                 <item>
                  <layout class="QHBoxLayout" name="horizontalLayout">
                   <item>
                    <widget class="QPushButton" name="pushButton">
                     <property name="minimumSize">
                      <size>
                       <width>40</width>
                       <height>40</height>
                      </size>
                     </property>
                     <property name="maximumSize">
                      <size>
                       <width>40</width>
                       <height>40</height>
                      </size>
                     </property>
                     <property name="text">
                      <string><-</string>
                     </property>
                    </widget>
                   </item>
                   <item>
                    <widget class="QStackedWidget" name="stackedWidget">
                     <property name="minimumSize">
                      <size>
                       <width>420</width>
                       <height>40</height>
                      </size>
                     </property>
                     <property name="maximumSize">
                      <size>
                       <width>16777215</width>
                       <height>40</height>
                      </size>
                     </property>
                     <property name="currentIndex">
                      <number>0</number>
                     </property>
                     <widget class="QWidget" name="page"/>
                     <widget class="QWidget" name="page_2"/>
                    </widget>
                   </item>
                   <item>
                    <widget class="QLabel" name="count">
                     <property name="minimumSize">
                      <size>
                       <width>50</width>
                       <height>40</height>
                      </size>
                     </property>
                     <property name="maximumSize">
                      <size>
                       <width>70</width>
                       <height>40</height>
                      </size>
                     </property>
                     <property name="text">
                      <string>time</string>
                     </property>
                    </widget>
                   </item>
                   <item>
                    <widget class="QLabel" name="time">
                     <property name="minimumSize">
                      <size>
                       <width>70</width>
                       <height>40</height>
                      </size>
                     </property>
                     <property name="maximumSize">
                      <size>
                       <width>70</width>
                       <height>40</height>
                      </size>
                     </property>
                     <property name="text">
                      <string>time1</string>
                     </property>
                    </widget>
                   </item>
                  </layout>
                 </item>
                </layout>
               </widget>
              </widget>
             </widget>
             <resources/>
             <connections/>
            </ui>
            

            But how do I make qhboxlayout always stay at the bottom and stick to both sides of the gui even when I change the window size?

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

            @a_coder
            Hi. I believe you will find your design is not "correct", and I would start by getting that right.

            In the Object Inspector at the right you can see your centralWidget has a "red no-entry" sign on it. That tells you it is a widget which needs to have a layout but lacks one. I don't believe there is any (common) situation in which you want to leave it like that.

            You have placed a new widget, which has a vertical layout, directly onto centralWidget. Instead you should have selected centralWidget, right-clicked on it, and used the bottom item on the menu there to set a vertical layout on the centralWidget. There should be no "no-entry" sign then. (Note that, irritatingly, Designer only allows you set a widget's layout after you have added at least one item onto it, not when it's empty.) You can then place your horizontalLayout onto that.

            It's fiddly to remove content and then put it elsewhere in Designer, it's probably easier for you to delete/start over.

            I see others have posted while I have been composing this. (Though I do not see any need for a QGridLayout here.) Hopefully my post will help you sort that part out.

            A 2 Replies Last reply
            1
            • JonBJ JonB

              @a_coder
              Hi. I believe you will find your design is not "correct", and I would start by getting that right.

              In the Object Inspector at the right you can see your centralWidget has a "red no-entry" sign on it. That tells you it is a widget which needs to have a layout but lacks one. I don't believe there is any (common) situation in which you want to leave it like that.

              You have placed a new widget, which has a vertical layout, directly onto centralWidget. Instead you should have selected centralWidget, right-clicked on it, and used the bottom item on the menu there to set a vertical layout on the centralWidget. There should be no "no-entry" sign then. (Note that, irritatingly, Designer only allows you set a widget's layout after you have added at least one item onto it, not when it's empty.) You can then place your horizontalLayout onto that.

              It's fiddly to remove content and then put it elsewhere in Designer, it's probably easier for you to delete/start over.

              I see others have posted while I have been composing this. (Though I do not see any need for a QGridLayout here.) Hopefully my post will help you sort that part out.

              A Offline
              A Offline
              a_coder
              wrote on last edited by
              #5
              This post is deleted!
              1 Reply Last reply
              0
              • JonBJ JonB

                @a_coder
                Hi. I believe you will find your design is not "correct", and I would start by getting that right.

                In the Object Inspector at the right you can see your centralWidget has a "red no-entry" sign on it. That tells you it is a widget which needs to have a layout but lacks one. I don't believe there is any (common) situation in which you want to leave it like that.

                You have placed a new widget, which has a vertical layout, directly onto centralWidget. Instead you should have selected centralWidget, right-clicked on it, and used the bottom item on the menu there to set a vertical layout on the centralWidget. There should be no "no-entry" sign then. (Note that, irritatingly, Designer only allows you set a widget's layout after you have added at least one item onto it, not when it's empty.) You can then place your horizontalLayout onto that.

                It's fiddly to remove content and then put it elsewhere in Designer, it's probably easier for you to delete/start over.

                I see others have posted while I have been composing this. (Though I do not see any need for a QGridLayout here.) Hopefully my post will help you sort that part out.

                A Offline
                A Offline
                a_coder
                wrote on last edited by a_coder
                #6

                @JonB it's work now how can i keep it in the bottom when i resize it?

                JonBJ 1 Reply Last reply
                0
                • A a_coder

                  @JonB it's work now how can i keep it in the bottom when i resize it?

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

                  @a_coder
                  As both other responders said, you need a vertical spacer above a widget if you want to push it down.

                  1 Reply Last reply
                  0
                  • A a_coder 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