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. Auto resize contents when dialog is resized?
Qt 6.11 is out! See what's new in the release blog

Auto resize contents when dialog is resized?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 2 Posters 2.0k 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    I've added a QFormLayout to the centralWidget, the layoutFieldGrowthPolicy is set to ExpandingFieldsGrow, all the labels and other widgets have been added to the form layout, but when I resize the dialog, nothing happens, everything stays the same size...what haven't I done?

    Kind Regards,
    Sy

    jsulmJ 1 Reply Last reply
    0
    • SPlattenS SPlatten

      @jsulm , here is the XML for the UI file:

      <?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>519</width>
          <height>409</height>
         </rect>
        </property>
        <property name="sizePolicy">
        <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
          <horstretch>0</horstretch>
          <verstretch>0</verstretch>
         </sizepolicy>
        </property>
        <property name="windowTitle">
         <string>MainWindow</string>
        </property>
        <widget class="QWidget" name="centralWidget">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <widget class="QWidget" name="formLayoutWidget">
          <property name="geometry">
           <rect>
            <x>10</x>
            <y>0</y>
            <width>501</width>
            <height>391</height>
           </rect>
          </property>
          <layout class="QFormLayout" name="formLayout">
           <property name="fieldGrowthPolicy">
            <enum>QFormLayout::ExpandingFieldsGrow</enum>
           </property>
           <item row="0" column="0">
            <widget class="QLabel" name="label">
             <property name="text">
              <string>Received:</string>
             </property>
            </widget>
           </item>
           <item row="2" column="0">
            <widget class="QLabel" name="label_2">
             <property name="text">
              <string>Response:</string>
             </property>
            </widget>
           </item>
           <item row="1" column="0" colspan="2">
            <widget class="QListWidget" name="plwRx"/>
           </item>
           <item row="3" column="0" colspan="2">
            <widget class="QListWidget" name="plwTx"/>
           </item>
          </layout>
         </widget>
        </widget>
        <widget class="QToolBar" name="mainToolBar">
         <attribute name="toolBarArea">
          <enum>TopToolBarArea</enum>
         </attribute>
         <attribute name="toolBarBreak">
          <bool>false</bool>
         </attribute>
        </widget>
      </widget>
      <layoutdefault spacing="6" margin="11"/>
      <resources/>
      <connections/>
      </ui>
      

      And a screenshot of the layout in Qt Creator:
      QtCreator.png

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @SPlatten Yes, your dialog has no top-layout (you can even see that in designer if you resize the dialog). Right-click on an empty space in your dialog and then select Layout->one_of_the_layouts...

      SPlattenS 1 Reply Last reply
      1
      • SPlattenS SPlatten

        I've added a QFormLayout to the centralWidget, the layoutFieldGrowthPolicy is set to ExpandingFieldsGrow, all the labels and other widgets have been added to the form layout, but when I resize the dialog, nothing happens, everything stays the same size...what haven't I done?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @SPlatten said in Auto resize contents when dialog is resized?:

        what haven't I done?

        Without more information (code or design screen-shot) hard to say. Probably you did not apply the layout to the dialog.

        SPlattenS 1 Reply Last reply
        1
        • jsulmJ jsulm

          @SPlatten said in Auto resize contents when dialog is resized?:

          what haven't I done?

          Without more information (code or design screen-shot) hard to say. Probably you did not apply the layout to the dialog.

          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by
          #3

          @jsulm , here is the XML for the UI file:

          <?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>519</width>
              <height>409</height>
             </rect>
            </property>
            <property name="sizePolicy">
            <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
              <horstretch>0</horstretch>
              <verstretch>0</verstretch>
             </sizepolicy>
            </property>
            <property name="windowTitle">
             <string>MainWindow</string>
            </property>
            <widget class="QWidget" name="centralWidget">
             <property name="sizePolicy">
              <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
               <horstretch>0</horstretch>
               <verstretch>0</verstretch>
              </sizepolicy>
             </property>
             <widget class="QWidget" name="formLayoutWidget">
              <property name="geometry">
               <rect>
                <x>10</x>
                <y>0</y>
                <width>501</width>
                <height>391</height>
               </rect>
              </property>
              <layout class="QFormLayout" name="formLayout">
               <property name="fieldGrowthPolicy">
                <enum>QFormLayout::ExpandingFieldsGrow</enum>
               </property>
               <item row="0" column="0">
                <widget class="QLabel" name="label">
                 <property name="text">
                  <string>Received:</string>
                 </property>
                </widget>
               </item>
               <item row="2" column="0">
                <widget class="QLabel" name="label_2">
                 <property name="text">
                  <string>Response:</string>
                 </property>
                </widget>
               </item>
               <item row="1" column="0" colspan="2">
                <widget class="QListWidget" name="plwRx"/>
               </item>
               <item row="3" column="0" colspan="2">
                <widget class="QListWidget" name="plwTx"/>
               </item>
              </layout>
             </widget>
            </widget>
            <widget class="QToolBar" name="mainToolBar">
             <attribute name="toolBarArea">
              <enum>TopToolBarArea</enum>
             </attribute>
             <attribute name="toolBarBreak">
              <bool>false</bool>
             </attribute>
            </widget>
          </widget>
          <layoutdefault spacing="6" margin="11"/>
          <resources/>
          <connections/>
          </ui>
          

          And a screenshot of the layout in Qt Creator:
          QtCreator.png

          Kind Regards,
          Sy

          jsulmJ 1 Reply Last reply
          0
          • SPlattenS SPlatten

            @jsulm , here is the XML for the UI file:

            <?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>519</width>
                <height>409</height>
               </rect>
              </property>
              <property name="sizePolicy">
              <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
                <horstretch>0</horstretch>
                <verstretch>0</verstretch>
               </sizepolicy>
              </property>
              <property name="windowTitle">
               <string>MainWindow</string>
              </property>
              <widget class="QWidget" name="centralWidget">
               <property name="sizePolicy">
                <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
                 <horstretch>0</horstretch>
                 <verstretch>0</verstretch>
                </sizepolicy>
               </property>
               <widget class="QWidget" name="formLayoutWidget">
                <property name="geometry">
                 <rect>
                  <x>10</x>
                  <y>0</y>
                  <width>501</width>
                  <height>391</height>
                 </rect>
                </property>
                <layout class="QFormLayout" name="formLayout">
                 <property name="fieldGrowthPolicy">
                  <enum>QFormLayout::ExpandingFieldsGrow</enum>
                 </property>
                 <item row="0" column="0">
                  <widget class="QLabel" name="label">
                   <property name="text">
                    <string>Received:</string>
                   </property>
                  </widget>
                 </item>
                 <item row="2" column="0">
                  <widget class="QLabel" name="label_2">
                   <property name="text">
                    <string>Response:</string>
                   </property>
                  </widget>
                 </item>
                 <item row="1" column="0" colspan="2">
                  <widget class="QListWidget" name="plwRx"/>
                 </item>
                 <item row="3" column="0" colspan="2">
                  <widget class="QListWidget" name="plwTx"/>
                 </item>
                </layout>
               </widget>
              </widget>
              <widget class="QToolBar" name="mainToolBar">
               <attribute name="toolBarArea">
                <enum>TopToolBarArea</enum>
               </attribute>
               <attribute name="toolBarBreak">
                <bool>false</bool>
               </attribute>
              </widget>
            </widget>
            <layoutdefault spacing="6" margin="11"/>
            <resources/>
            <connections/>
            </ui>
            

            And a screenshot of the layout in Qt Creator:
            QtCreator.png

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @SPlatten Yes, your dialog has no top-layout (you can even see that in designer if you resize the dialog). Right-click on an empty space in your dialog and then select Layout->one_of_the_layouts...

            SPlattenS 1 Reply Last reply
            1
            • jsulmJ jsulm

              @SPlatten Yes, your dialog has no top-layout (you can even see that in designer if you resize the dialog). Right-click on an empty space in your dialog and then select Layout->one_of_the_layouts...

              SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by
              #5

              @jsulm , I'm confused now, is the centralWidget required at all?

              Kind Regards,
              Sy

              jsulmJ 2 Replies Last reply
              0
              • SPlattenS SPlatten

                @jsulm , I'm confused now, is the centralWidget required at all?

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #6
                This post is deleted!
                SPlattenS 1 Reply Last reply
                0
                • jsulmJ jsulm

                  This post is deleted!

                  SPlattenS Offline
                  SPlattenS Offline
                  SPlatten
                  wrote on last edited by
                  #7

                  @jsulm , trying it now.

                  Kind Regards,
                  Sy

                  1 Reply Last reply
                  0
                  • SPlattenS SPlatten

                    @jsulm , I'm confused now, is the centralWidget required at all?

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    @SPlatten A QDialog is already a QWidget. So, no there is no need for central widget.

                    SPlattenS 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @SPlatten A QDialog is already a QWidget. So, no there is no need for central widget.

                      SPlattenS Offline
                      SPlattenS Offline
                      SPlatten
                      wrote on last edited by
                      #9

                      @jsulm , works now :) thank you.

                      Kind Regards,
                      Sy

                      1 Reply Last reply
                      0

                      • Login

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