Qt Designed and Grid Layout: how to span multiple columns/rows?
Is it possible, with the designed, configure a widget to span over multiple columns/rows, as I can do width addWidget()?
5 replies
I just tried it: yes, it is.
- <?xml version="1.0" encoding="UTF-8"?>
- <ui version="4.0">
- <class>Form</class>
- <widget class="QWidget" name="Form">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>193</width>
- <height>85</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Form</string>
- </property>
- <widget class="QWidget" name="">
- <property name="geometry">
- <rect>
- <x>10</x>
- <y>10</y>
- <width>158</width>
- <height>54</height>
- </rect>
- </property>
- <layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0">
- <widget class="QPushButton" name="pushButton">
- <property name="text">
- <string>PushButton</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QPushButton" name="pushButton_2">
- <property name="text">
- <string>PushButton</string>
- </property>
- </widget>
- </item>
- <item row="1" column="0" colspan="2">
- <widget class="QPushButton" name="pushButton_3">
- <property name="text">
- <string>PushButton</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </widget>
- <resources/>
- <connections/>
- </ui>
No, I created the file completely with designer itself.
What I did was drop the three buttons in roughly the way I wanted them (so with the bottom botton spanning the width of both top buttons together), selected them, and applied a grid layout on them. I pasted the resulting .ui file.
Edit:
You can also change it later. I just dropped an additional button on the grid on the right, and Qt Designer created another column and put the button in the new top-right cell. Now I just dragged the button’s bottom edge downwards, over the border of the cell, and Designer made the top right cell span two rows and put the button in the middle of it.
Feels quite natural to me.
You must log in to post a reply. Not a member yet? Register here!


