Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problems using qsizepolicy in a qgridayout



  • 0_1564237711576_Screenshot from 2019-07-27 16-19-57.png
    The above image shows part of a larger gridlayout. The leftmost item at the bottom row ("Surface waves") is the problem. The top lefthand item ("Air temp.") is wider than the righthand items. I wish "Surface waves" to have the same width as "Air temp." I have spent a whole day on this without any success. I have used about all possible values for the size policy of "Surface waves" but have not had any success. Following is my code for the item "Surface waves".

       <item row="1" column="0" alignment="Qt::AlignLeft">
        <widget class="QGroupBox" name="groupBox_waves">
         <property name="title">
          <string>Surface waves</string>
         </property>
         <property name="alignment">
          <set>Qt::AlignHCenter</set>
         </property> 
    
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
           <horstretch>1</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
    
         <layout class="QGridLayout" name="surfaceWavesLayout">
          <property name="verticalSpacing">
           <number>0</number>
          </property>
          <item row="0" column="0" colspan="2" alignment="Qt::AlignHCenter">
           <widget class="StarWidget" name="waves" native="true">
            <property name="focusPolicy">
             <enum>Qt::StrongFocus</enum>
            </property>
            <property name="sizePolicy">
             <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
              <horstretch>0</horstretch>
              <verstretch>0</verstretch>
             </sizepolicy>
            </property>
    
           </widget>
          </item>
          <item row="1" column="0" alignment="Qt::AlignLeft">
           <widget class="QLabel" name="waveLabel1">
            <property name="text">
             <string>Small</string>
            </property>
           </widget>
           </item>
           <item row="1" column="1" alignment="Qt::AlignRight">
            <widget class="QLabel" name="waveLabel2">
             <property name="text">
              <string>Large</string>
             </property>
           </widget>
          </item>
         </layout>
        </widget>
       </item>
    

    I hope this gives sufficient information to locate my problem. I would appreiate any suggestions. Kind regards, willem


  • Moderators

    It's probably because of the alignment you set to Qt::AlignLeft. This alignment is for cases when you don't want an item to fill grid's cell or it has a maximum size smaller than the cell. It then says which border do you want your item to stick to.

    If you want it to fill the cell leave it at default i.e. remove alignment="Qt::AlignLeft" from item definition.


Log in to reply