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()?



  • 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>
    @



  • [quote author="Andre" date="1295256652"]I just tried it: yes, it is.

    @
    <layout class="QGridLayout" name="gridLayout">
    ...
    <item row="1" column="0" colspan="2">
    ...
    @[/quote]

    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).



  • 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.



  • ! 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



  • That's a nice feature. I am not going mad anymore with layouts :-)
    [quote author="calberto" date="1295258628"]! 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
    [/quote]



  • The answer that keeps on giving. Thanks that was driving me nuts trying to get a button box to span across the bottom of a 3 column grid layout.



  • The answer that keeps on giving. Thanks that was driving me nuts trying to get a button box to span across the bottom of a 3 column grid layout.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.