January 17, 2011

calberto calberto
Lab Rat
18 posts

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

January 17, 2011

Andre Andre
Area 51 Engineer
6031 posts

I just tried it: yes, it is.

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <ui version="4.0">
  3.  <class>Form</class>
  4.  <widget class="QWidget" name="Form">
  5.   <property name="geometry">
  6.    <rect>
  7.     <x>0</x>
  8.     <y>0</y>
  9.     <width>193</width>
  10.     <height>85</height>
  11.    </rect>
  12.   </property>
  13.   <property name="windowTitle">
  14.    <string>Form</string>
  15.   </property>
  16.   <widget class="QWidget" name="">
  17.    <property name="geometry">
  18.     <rect>
  19.      <x>10</x>
  20.      <y>10</y>
  21.      <width>158</width>
  22.      <height>54</height>
  23.     </rect>
  24.    </property>
  25.    <layout class="QGridLayout" name="gridLayout">
  26.     <item row="0" column="0">
  27.      <widget class="QPushButton" name="pushButton">
  28.       <property name="text">
  29.        <string>PushButton</string>
  30.       </property>
  31.      </widget>
  32.     </item>
  33.     <item row="0" column="1">
  34.      <widget class="QPushButton" name="pushButton_2">
  35.       <property name="text">
  36.        <string>PushButton</string>
  37.       </property>
  38.      </widget>
  39.     </item>
  40.     <item row="1" column="0" colspan="2">
  41.      <widget class="QPushButton" name="pushButton_3">
  42.       <property name="text">
  43.        <string>PushButton</string>
  44.       </property>
  45.      </widget>
  46.     </item>
  47.    </layout>
  48.   </widget>
  49.  </widget>
  50.  <resources/>
  51.  <connections/>
  52. </ui>

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

January 17, 2011

calberto calberto
Lab Rat
18 posts

Andre wrote:
I just tried it: yes, it is.

@ <layout class=“QGridLayout” name=“gridLayout”> … <item row=“1” column=“0” colspan=“2”> …
@

Do You mean I have to manually change the ui file? I cannot find I “visual” way to do it inside the Qt Designer (running from Qt Creator on Windows XP, Qt 4.7.0).

January 17, 2011

Andre Andre
Area 51 Engineer
6031 posts

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.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

January 17, 2011

calberto calberto
Lab Rat
18 posts

! Its was too simple to find! I’m sorry. It can also be done on an existing layout by simple dragging a side of a widget over the adjacent cell.

Thanks

January 17, 2011

Mattias Cibien Mattias Cibien
Lab Rat
66 posts

That’s a nice feature. I am not going mad anymore with layouts :-)

calberto wrote:
! Its was too simple to find! I’m sorry. It can also be done on an existing layout by simple dragging a side of a widget over the adjacent cell.

Thanks

 Signature 

http://mattias-cibien.co.cc
- Prepare for Qt consequences.

 
  ‹‹ Qt Simulator - does it support pinch-to-zoom?      CellsColor in the QTableView ››

You must log in to post a reply. Not a member yet? Register here!