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. newbie question: how to set a fixed height of a set of Widgets
Forum Updated to NodeBB v4.3 + New Features

newbie question: how to set a fixed height of a set of Widgets

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 3 Posters 1.6k 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.
  • M mpergand

    @cdvo said in newbie question: how to set a fixed height of a set of Widgets:

    The Layout Alignment menu item is gray out in my case.

    Strange, if you try with the other widgets, does the menu grayed as well ?
    You can try to right click on the button in the object tree panel in the top right corner.
    I'm using Qt 5.15.2 QtCreator 10.0.1 on Mac,
    but I don't think it makes any difference since it is a very old fonctionality.

    C Offline
    C Offline
    cdvo
    wrote on last edited by
    #9

    @mpergand

    Thanks a lot! You found the bug.

    After your comments I made a test and build the same layout with all the Designer version I have under Windows 10:

    • QT Designer 5.15.2 x32 -> the layout alignment works
    • QT Designer 5.15.2 x64 -> the layout alignment doesn't work
    • QT Designer 6.6.1 x64 -> the layout alignment works

    Unless I messed up something with the 64 bit version of 5.15.2 Designer, then that is a bug.

    Again, thanks

    C 1 Reply Last reply
    0
    • C cdvo

      @mpergand

      Thanks a lot! You found the bug.

      After your comments I made a test and build the same layout with all the Designer version I have under Windows 10:

      • QT Designer 5.15.2 x32 -> the layout alignment works
      • QT Designer 5.15.2 x64 -> the layout alignment doesn't work
      • QT Designer 6.6.1 x64 -> the layout alignment works

      Unless I messed up something with the 64 bit version of 5.15.2 Designer, then that is a bug.

      Again, thanks

      C Offline
      C Offline
      cdvo
      wrote on last edited by
      #10

      Now I can come back to my initial intent.
      I needed more than one push button on the right of the bottom table.
      If I start with only one button top aligned and add a second button, the horizontal layout
      is in charge and I get this output

      d37848b6-e2a7-4445-9761-e2e96a19f79a-image.png

      It comes without saying that for getting the buttons vertically aligned, one on top of the other, I need to put them inside a vertical layout.
      But once they are inside a vertical layout, they are automatically and proportionally vertical centered, even if I align
      them on the top

      2b4cf508-9d26-4118-bf56-e00341c430b1-image.png

      So my initiall question was, how can I get this result with QT layouts?

      49115e74-b6f4-4ae2-93ae-f33e8588c287-image.png

      Thank you!

      Pl45m4P M 2 Replies Last reply
      0
      • C cdvo

        Now I can come back to my initial intent.
        I needed more than one push button on the right of the bottom table.
        If I start with only one button top aligned and add a second button, the horizontal layout
        is in charge and I get this output

        d37848b6-e2a7-4445-9761-e2e96a19f79a-image.png

        It comes without saying that for getting the buttons vertically aligned, one on top of the other, I need to put them inside a vertical layout.
        But once they are inside a vertical layout, they are automatically and proportionally vertical centered, even if I align
        them on the top

        2b4cf508-9d26-4118-bf56-e00341c430b1-image.png

        So my initiall question was, how can I get this result with QT layouts?

        49115e74-b6f4-4ae2-93ae-f33e8588c287-image.png

        Thank you!

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

        @cdvo said in newbie question: how to set a fixed height of a set of Widgets:

        So my initiall question was, how can I get this result with QT layouts?

        Remove the whole Layout Alignment stuff and put a vertical spacer below your buttons.
        Since you are mainly using the Designer, it's simply drag'n'drop.

        Or by code

        QSpacerItem *vSpacer = new QSpacerItem(0,0, QSizePolicy::Minimum
                                                   , QSizePolicy::Expanding);
        ui->verticalLayout->addItem(vSpacer);
        

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

        ~E. W. Dijkstra

        C 1 Reply Last reply
        0
        • C cdvo

          Now I can come back to my initial intent.
          I needed more than one push button on the right of the bottom table.
          If I start with only one button top aligned and add a second button, the horizontal layout
          is in charge and I get this output

          d37848b6-e2a7-4445-9761-e2e96a19f79a-image.png

          It comes without saying that for getting the buttons vertically aligned, one on top of the other, I need to put them inside a vertical layout.
          But once they are inside a vertical layout, they are automatically and proportionally vertical centered, even if I align
          them on the top

          2b4cf508-9d26-4118-bf56-e00341c430b1-image.png

          So my initiall question was, how can I get this result with QT layouts?

          49115e74-b6f4-4ae2-93ae-f33e8588c287-image.png

          Thank you!

          M Offline
          M Offline
          mpergand
          wrote on last edited by mpergand
          #12

          @cdvo
          Yeah, things starting going tricky ...

          You have to add a vertical spacer after the buttons, but a border appears around the table because you set it a maximum size. Looks like a dead end ...

          A solution could be to set a layout strech of 3,1 to the vertical layout (central widget).

          1 Reply Last reply
          0
          • Pl45m4P Pl45m4

            @cdvo said in newbie question: how to set a fixed height of a set of Widgets:

            So my initiall question was, how can I get this result with QT layouts?

            Remove the whole Layout Alignment stuff and put a vertical spacer below your buttons.
            Since you are mainly using the Designer, it's simply drag'n'drop.

            Or by code

            QSpacerItem *vSpacer = new QSpacerItem(0,0, QSizePolicy::Minimum
                                                       , QSizePolicy::Expanding);
            ui->verticalLayout->addItem(vSpacer);
            
            C Offline
            C Offline
            cdvo
            wrote on last edited by
            #13

            @Pl45m4
            Already tried.

            If I do that I got similar effect as in my second screenshot from the beginning of this thread.

            Thanks

            M Pl45m4P 2 Replies Last reply
            0
            • C cdvo

              @Pl45m4
              Already tried.

              If I do that I got similar effect as in my second screenshot from the beginning of this thread.

              Thanks

              M Offline
              M Offline
              mpergand
              wrote on last edited by
              #14

              @cdvo
              Save this with .ui extension and have a try.

              <?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>800</width>
                  <height>600</height>
                 </rect>
                </property>
                <property name="windowTitle">
                 <string>MainWindow</string>
                </property>
                <widget class="QWidget" name="centralwidget">
                 <layout class="QVBoxLayout" name="verticalLayout" stretch="4,1">
                  <item>
                   <widget class="QTableView" name="tableView"/>
                  </item>
                  <item>
                   <layout class="QHBoxLayout" name="horizontalLayout">
                    <property name="spacing">
                     <number>-1</number>
                    </property>
                    <item>
                     <widget class="QWidget" name="widget" native="true">
                      <property name="sizePolicy">
                       <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
                        <horstretch>0</horstretch>
                        <verstretch>0</verstretch>
                       </sizepolicy>
                      </property>
                      <property name="minimumSize">
                       <size>
                        <width>0</width>
                        <height>100</height>
                       </size>
                      </property>
                      <property name="maximumSize">
                       <size>
                        <width>16777215</width>
                        <height>100</height>
                       </size>
                      </property>
                      <layout class="QHBoxLayout" name="horizontalLayout_2">
                       <property name="leftMargin">
                        <number>0</number>
                       </property>
                       <property name="topMargin">
                        <number>0</number>
                       </property>
                       <property name="rightMargin">
                        <number>0</number>
                       </property>
                       <property name="bottomMargin">
                        <number>0</number>
                       </property>
                       <item>
                        <widget class="QTableView" name="tableView_2">
                         <property name="sizePolicy">
                          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
                           <horstretch>0</horstretch>
                           <verstretch>0</verstretch>
                          </sizepolicy>
                         </property>
                         <property name="minimumSize">
                          <size>
                           <width>0</width>
                           <height>0</height>
                          </size>
                         </property>
                         <property name="maximumSize">
                          <size>
                           <width>16777215</width>
                           <height>10000</height>
                          </size>
                         </property>
                        </widget>
                       </item>
                       <item>
                        <layout class="QVBoxLayout" name="verticalLayout_2">
                         <property name="spacing">
                          <number>-1</number>
                         </property>
                         <property name="sizeConstraint">
                          <enum>QLayout::SetFixedSize</enum>
                         </property>
                         <property name="bottomMargin">
                          <number>0</number>
                         </property>
                         <item>
                          <widget class="QPushButton" name="pushButton">
                           <property name="text">
                            <string>PushButton</string>
                           </property>
                          </widget>
                         </item>
                         <item>
                          <widget class="QPushButton" name="pushButton_2">
                           <property name="text">
                            <string>PushButton</string>
                           </property>
                          </widget>
                         </item>
                         <item>
                          <spacer name="verticalSpacer">
                           <property name="orientation">
                            <enum>Qt::Vertical</enum>
                           </property>
                           <property name="sizeHint" stdset="0">
                            <size>
                             <width>20</width>
                             <height>40</height>
                            </size>
                           </property>
                          </spacer>
                         </item>
                        </layout>
                       </item>
                      </layout>
                     </widget>
                    </item>
                   </layout>
                  </item>
                 </layout>
                </widget>
                <widget class="QMenuBar" name="menubar">
                 <property name="geometry">
                  <rect>
                   <x>0</x>
                   <y>0</y>
                   <width>800</width>
                   <height>22</height>
                  </rect>
                 </property>
                </widget>
                <widget class="QStatusBar" name="statusbar"/>
               </widget>
               <resources/>
               <connections/>
              </ui>
              
              
              C 1 Reply Last reply
              0
              • C cdvo

                @Pl45m4
                Already tried.

                If I do that I got similar effect as in my second screenshot from the beginning of this thread.

                Thanks

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

                @cdvo said in newbie question: how to set a fixed height of a set of Widgets:

                If I do that I got similar effect as in my second screenshot from the beginning of this thread.

                I dont know what you did, but I can get your desired result easily by doing what I've written above.
                Both button pushed to the top, and aligned with the QTableView

                Alignment2.png

                Result:

                Alignment1.png

                Edit:

                Even with QTableView's vertical settings set to fixed, it works.


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

                ~E. W. Dijkstra

                C 1 Reply Last reply
                0
                • M mpergand

                  @cdvo
                  Save this with .ui extension and have a try.

                  <?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>800</width>
                      <height>600</height>
                     </rect>
                    </property>
                    <property name="windowTitle">
                     <string>MainWindow</string>
                    </property>
                    <widget class="QWidget" name="centralwidget">
                     <layout class="QVBoxLayout" name="verticalLayout" stretch="4,1">
                      <item>
                       <widget class="QTableView" name="tableView"/>
                      </item>
                      <item>
                       <layout class="QHBoxLayout" name="horizontalLayout">
                        <property name="spacing">
                         <number>-1</number>
                        </property>
                        <item>
                         <widget class="QWidget" name="widget" native="true">
                          <property name="sizePolicy">
                           <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
                            <horstretch>0</horstretch>
                            <verstretch>0</verstretch>
                           </sizepolicy>
                          </property>
                          <property name="minimumSize">
                           <size>
                            <width>0</width>
                            <height>100</height>
                           </size>
                          </property>
                          <property name="maximumSize">
                           <size>
                            <width>16777215</width>
                            <height>100</height>
                           </size>
                          </property>
                          <layout class="QHBoxLayout" name="horizontalLayout_2">
                           <property name="leftMargin">
                            <number>0</number>
                           </property>
                           <property name="topMargin">
                            <number>0</number>
                           </property>
                           <property name="rightMargin">
                            <number>0</number>
                           </property>
                           <property name="bottomMargin">
                            <number>0</number>
                           </property>
                           <item>
                            <widget class="QTableView" name="tableView_2">
                             <property name="sizePolicy">
                              <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
                               <horstretch>0</horstretch>
                               <verstretch>0</verstretch>
                              </sizepolicy>
                             </property>
                             <property name="minimumSize">
                              <size>
                               <width>0</width>
                               <height>0</height>
                              </size>
                             </property>
                             <property name="maximumSize">
                              <size>
                               <width>16777215</width>
                               <height>10000</height>
                              </size>
                             </property>
                            </widget>
                           </item>
                           <item>
                            <layout class="QVBoxLayout" name="verticalLayout_2">
                             <property name="spacing">
                              <number>-1</number>
                             </property>
                             <property name="sizeConstraint">
                              <enum>QLayout::SetFixedSize</enum>
                             </property>
                             <property name="bottomMargin">
                              <number>0</number>
                             </property>
                             <item>
                              <widget class="QPushButton" name="pushButton">
                               <property name="text">
                                <string>PushButton</string>
                               </property>
                              </widget>
                             </item>
                             <item>
                              <widget class="QPushButton" name="pushButton_2">
                               <property name="text">
                                <string>PushButton</string>
                               </property>
                              </widget>
                             </item>
                             <item>
                              <spacer name="verticalSpacer">
                               <property name="orientation">
                                <enum>Qt::Vertical</enum>
                               </property>
                               <property name="sizeHint" stdset="0">
                                <size>
                                 <width>20</width>
                                 <height>40</height>
                                </size>
                               </property>
                              </spacer>
                             </item>
                            </layout>
                           </item>
                          </layout>
                         </widget>
                        </item>
                       </layout>
                      </item>
                     </layout>
                    </widget>
                    <widget class="QMenuBar" name="menubar">
                     <property name="geometry">
                      <rect>
                       <x>0</x>
                       <y>0</y>
                       <width>800</width>
                       <height>22</height>
                      </rect>
                     </property>
                    </widget>
                    <widget class="QStatusBar" name="statusbar"/>
                   </widget>
                   <resources/>
                   <connections/>
                  </ui>
                  
                  
                  C Offline
                  C Offline
                  cdvo
                  wrote on last edited by
                  #16

                  @mpergand
                  I tested your ui file and indeed does what I expected.

                  The trick in your case is to wrap the bottom table and the column of buttons inside a QWidget instead of wrapping them only with the horizontal layout, isn'it?

                  Thanks

                  M 1 Reply Last reply
                  0
                  • C cdvo

                    @mpergand
                    I tested your ui file and indeed does what I expected.

                    The trick in your case is to wrap the bottom table and the column of buttons inside a QWidget instead of wrapping them only with the horizontal layout, isn'it?

                    Thanks

                    M Offline
                    M Offline
                    mpergand
                    wrote on last edited by mpergand
                    #17

                    @cdvo said in newbie question: how to set a fixed height of a set of Widgets:

                    The trick in your case is to wrap the bottom table and the column of buttons inside a QWidget instead of wrapping them only with the horizontal layout, isn'it?

                    Yes, because without this, only the table is size constrainted, not the buttons.

                    In fact you circonvent the normal behavior of layouts, so the need to fiddling around .

                    Actually, in cases like yours, it's more usual to use splitters instead.

                    C 1 Reply Last reply
                    1
                    • Pl45m4P Pl45m4

                      @cdvo said in newbie question: how to set a fixed height of a set of Widgets:

                      If I do that I got similar effect as in my second screenshot from the beginning of this thread.

                      I dont know what you did, but I can get your desired result easily by doing what I've written above.
                      Both button pushed to the top, and aligned with the QTableView

                      Alignment2.png

                      Result:

                      Alignment1.png

                      Edit:

                      Even with QTableView's vertical settings set to fixed, it works.

                      C Offline
                      C Offline
                      cdvo
                      wrote on last edited by
                      #18

                      @Pl45m4

                      I dont know what you did,

                      Exactly what you suggest to do.

                      but I can get your desired result easily by doing what I've written above.
                      Both button pushed to the top, and aligned with the QTableView

                      I know. After that, when you lay out at the end the entire central widget you will see the vertical layout (with buttons and vertical spacer) growing more than the fixed height I wanted.

                      Could you please share your ui?

                      Thanks for your help

                      1 Reply Last reply
                      0
                      • M mpergand

                        @cdvo said in newbie question: how to set a fixed height of a set of Widgets:

                        The trick in your case is to wrap the bottom table and the column of buttons inside a QWidget instead of wrapping them only with the horizontal layout, isn'it?

                        Yes, because without this, only the table is size constrainted, not the buttons.

                        In fact you circonvent the normal behavior of layouts, so the need to fiddling around .

                        Actually, in cases like yours, it's more usual to use splitters instead.

                        C Offline
                        C Offline
                        cdvo
                        wrote on last edited by
                        #19

                        @mpergand

                        In fact you circonvent the normal behavior of layouts, so the need to fiddling around .

                        My intention was to get my desired layout using only horizontal and vertical layouts, optionally with grid layouts,
                        and their properties.

                        Yes, because without this, only the table is size constrainted, not the buttons.

                        My knowledge of Qt is still very poor, but why the vertical layout containing the buttons and the spacer doesn't honor
                        the layoutSizeConstraint property set to SetFixedSize but instead grows as in my second screenshot at the top
                        of this thread?

                        Thanks

                        1 Reply Last reply
                        0
                        • C cdvo 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