I have added a QScrollArea widget in QDialog form.
In the scrollarea, I have added 16 chcekboxes.
I want to loop inside the scrollarea and check for which of the checkboxes are checked.
Can anyone please help me with this. Thanks in advance!
The code for ScrollArea and Checkbox is like this:
<widget class="QScrollArea" name="scrollArea">
<property name="geometry">
<rect>
<x>20</x>
<y>320</y>
<width>271</width>
<height>206</height>
</rect>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>252</width>
<height>420</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QCheckBox" name="checkBox1">
<property name="text">
<string>1</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QCheckBox" name="checkBox7">
<property name="text">
<string>2</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="checkBox5">
<property name="text">
<string>3</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkBox2">
<property name="text">
<string>4</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="checkBox0">
<property name="text">
<string>5</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="checkBox3">
<property name="text">
<string>6</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="checkBox6">
<property name="text">
<string>7</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="checkBox4">
<property name="text">
<string>8</string>
</property>
</widget>
</item>
<item row="12" column="0">
<widget class="QCheckBox" name="checkBox12">
<property name="text">
<string>9</string>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QCheckBox" name="checkBox10">
<property name="text">
<string>10</string>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QCheckBox" name="checkBox11">
<property name="text">
<string>11</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QCheckBox" name="checkBox9">
<property name="text">
<string>Signal Mask</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QCheckBox" name="checkBox8">
<property name="text">
<string>12</string>
</property>
</widget>
</item>
<item row="15" column="0">
<widget class="QCheckBox" name="checkBox15">
<property name="text">
<string>13</string>
</property>
</widget>
</item>
<item row="14" column="0">
<widget class="QCheckBox" name="checkBox14">
<property name="text">
<string>14</string>
</property>
</widget>
</item>
<item row="13" column="0">
<widget class="QCheckBox" name="checkBox13">
<property name="text">
<string>15</string>
</property>
</widget>
</item>
<item row="16" column="0">
<widget class="QCheckBox" name="checkBox16">
<property name="text">
<string>16</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
This can be accomplished with the QObject::findChildren method.
An example code in your .cpp file that belongs to the .ui file would look like this:
QList<QCheckBox *> allCheckBoxes = this->findChildren<QCheckBox *>();
for (QCheckBox *checkBox: allCheckBoxes) {
if (checkBox->isChecked()) {
qDebug() << "CheckBox with object name " << checkBox->objectName() << " is checked";
}
}
Related
I'm not sure if this is a bug or the way QT Designer was designed but I cannot resize any element on a QT widget with the 'blue boxes' one would expect to resize with. I also am not allowed to edit the minimum/maximum sizes to anything but zero. Are there some settings I need to change or is this just a bug?
.UI file:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MeshGeneratorWidget</class>
<widget class="QWidget" name="MeshGeneratorWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>927</width>
<height>789</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Mesh Generator</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="AlignmentSceneviewerWidget" name="sceneviewer_widget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>4</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<widget class="QDockWidget" name="dockWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>-10</y>
<width>492</width>
<height>771</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>492</width>
<height>557</height>
</size>
</property>
<property name="features">
<set>QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable</set>
</property>
<property name="allowedAreas">
<set>Qt::AllDockWidgetAreas</set>
</property>
<property name="windowTitle">
<string>Control Panel</string>
</property>
<widget class="QWidget" name="dockWidgetContents">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>472</width>
<height>388</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="time_groupBox">
<property name="title">
<string>Time:</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="timeValue_doubleSpinBox">
<property name="maximum">
<double>12000.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QCheckBox" name="timeLoop_checkBox">
<property name="text">
<string>Loop</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="timeValue_label">
<property name="text">
<string>Time value:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="timePlayStop_pushButton">
<property name="text">
<string>Play</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>234</height>
</size>
</property>
<property name="title">
<string>Adjust Data</string>
</property>
<widget class="QSlider" name="adjustData_Slider">
<property name="geometry">
<rect>
<x>20</x>
<y>50</y>
<width>431</width>
<height>22</height>
</rect>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="minimum">
<number>-200</number>
</property>
<property name="maximum">
<number>200</number>
</property>
<property name="singleStep">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="invertedAppearance">
<bool>false</bool>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>410</x>
<y>70</y>
<width>55</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>+2s</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>30</x>
<y>70</y>
<width>55</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>-2s</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_3">
<property name="geometry">
<rect>
<x>60</x>
<y>170</y>
<width>201</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>View data with video</string>
</property>
</widget>
<widget class="QPushButton" name="viewVideo_button">
<property name="geometry">
<rect>
<x>180</x>
<y>90</y>
<width>121</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>View Video</string>
</property>
</widget>
</widget>
</item>
<item>
<widget class="QGroupBox" name="video_groupBox">
<property name="title">
<string>Video:</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="frameIndex_label">
<property name="text">
<string>Frame index:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="framesPerSecond_spinBox">
<property name="minimum">
<number>1</number>
</property>
<property name="value">
<number>25</number>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="frameIndex_spinBox">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="framesPerSecond_label">
<property name="text">
<string>Frames per second:</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QFrame" name="numFrames_frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="numFrames_label">
<property name="text">
<string># frames:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="numFramesValue_label">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>GroupBox</string>
</property>
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>200</x>
<y>0</y>
<width>113</width>
<height>20</height>
</rect>
</property>
</widget>
</widget>
</item>
<item>
<widget class="QGroupBox" name="blackfynn_groupBox">
<property name="title">
<string>Blackfynn:</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="6" column="2">
<widget class="QPushButton" name="downloadData_button">
<property name="text">
<string>Download Data</string>
</property>
</widget>
</item>
<item row="5" column="3">
<widget class="QPushButton" name="blackfynnTimeSeries_pushButton">
<property name="toolTip">
<string>Retrieve time series</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<normaloff>:/meshgeneratorstep/images/download-icon-blue.png</normaloff>:/meshgeneratorstep/images/download-icon-blue.png</iconset>
</property>
</widget>
</item>
<item row="9" column="2">
<widget class="QLineEdit" name="exportDirectory_lineEdit">
<property name="text">
<string>C:\Users\jkho021\Projects\MPB</string>
</property>
</widget>
</item>
<item row="7" column="2">
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Export for WebGL</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QComboBox" name="blackfynnDatasets_comboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="blackfynnDatasets_label">
<property name="text">
<string>Datasets:</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QPushButton" name="blackfynnDatasets_pushButton">
<property name="toolTip">
<string>Retrieve datasets</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<normaloff>:/meshgeneratorstep/images/download-icon-blue.png</normaloff>:/meshgeneratorstep/images/download-icon-blue.png</iconset>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QComboBox" name="blackfynnTimeSeries_comboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="blackfynnTimeSeries_label">
<property name="text">
<string>Time series:</string>
</property>
</widget>
</item>
<item row="8" column="2">
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>Upload to Blackfynn</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<widget class="QGroupBox" name="blackfynnProfiles_groupBox">
<property name="title">
<string>Profiles:</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QComboBox" name="profiles_comboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="addProfile_pushButton">
<property name="toolTip">
<string>Add profile</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<normaloff>:/meshgeneratorstep/images/plus-icon-green-th.png</normaloff>:/meshgeneratorstep/images/plus-icon-green-th.png</iconset>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="0">
<widget class="QFrame" name="frame_2">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QPushButton" name="viewAll_button">
<property name="text">
<string>View All</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="done_button">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Done</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>AlignmentSceneviewerWidget</class>
<extends>QWidget</extends>
<header>opencmiss/zincwidgets/alignmentsceneviewerwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="resources.qrc"/>
</resources>
<connections/>
</ui>
Not a bug. As ekhumoro mentioned above, you can't resize widgets that are contained in a layout (not with Designer, anyway). You need to break the layout, then resize, then reapply the layout. Kind of a pain, I know, but after awhile you get used to it. The toolbar buttons make this go a lot faster, BTW.
I am designing a simple GUI to do something and at a very early stage I find that QT is not behaving as I am expecting it to. I designed the ui file in QT Design and it looks like this:
However when I execute the python code and call the application, the object positions are all changed. I have tried converting the ui file to python file and the importing the ui file directly as well. But this has not changed the behavior.
Here is the code:
from __future__ import (
unicode_literals,
print_function,
division,
absolute_import
)
from PyQt4 import QtGui, QtCore, uic
from PyQt4.QtCore import QTime
from PyQt4.QtGui import QApplication
import main_gui
# class MyGUI(QtGui.QMainWindow, main_gui.Ui_MainWindow):
class MyGUI(QtGui.QMainWindow):
"""
The main class to execute the application
"""
def __init__(self, parent=None):
super(MyGUI, self).__init__(parent)
uic.loadUi('main_gui.ui', self)
# self.setupUi(self)
# self.showMaximized()
def main():
"""
But first we'll need to initialize that class on our code startup,
we'll handle the class instance creation and other stuff in our main()
function:
:return: Nothing
"""
app = QtGui.QApplication([])
form = MyGUI()
form.show()
app.exec()
if __name__ == '__main__':
main()
The output looks like this:
Here is a screen shot of my designer:
What am I doing wrong?
EDIT:
Upon request, I am attaching main.ui file. Here it is:
<?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>1143</width>
<height>865</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="Line" name="line_10">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="title">
<property name="minimumSize">
<size>
<width>200</width>
<height>40</height>
</size>
</property>
<property name="font">
<font>
<pointsize>20</pointsize>
</font>
</property>
<property name="mouseTracking">
<bool>false</bool>
</property>
<property name="text">
<string>Title</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item alignment="Qt::AlignLeft|Qt::AlignVCenter">
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<pointsize>24</pointsize>
</font>
</property>
<property name="text">
<string>SN</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item alignment="Qt::AlignRight|Qt::AlignVCenter">
<widget class="QLabel" name="sn">
<property name="font">
<font>
<pointsize>18</pointsize>
</font>
</property>
<property name="text">
<string>PPPPPPPPPPPPPPGSDB1YYDDDHHMMSS</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item alignment="Qt::AlignLeft|Qt::AlignVCenter">
<widget class="QLabel" name="label_4">
<property name="font">
<font>
<pointsize>18</pointsize>
</font>
</property>
<property name="text">
<string>Part Status</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item alignment="Qt::AlignRight|Qt::AlignVCenter">
<widget class="QLabel" name="part_status">
<property name="font">
<font>
<pointsize>26</pointsize>
</font>
</property>
<property name="text">
<string>NA</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item alignment="Qt::AlignLeft|Qt::AlignVCenter">
<widget class="QLabel" name="label_7">
<property name="font">
<font>
<pointsize>18</pointsize>
</font>
</property>
<property name="text">
<string>Tester Status</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_8">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item alignment="Qt::AlignRight|Qt::AlignVCenter">
<widget class="QLabel" name="tester_status">
<property name="font">
<font>
<pointsize>28</pointsize>
</font>
</property>
<property name="text">
<string>DOWN</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item alignment="Qt::AlignLeft|Qt::AlignVCenter">
<widget class="QLabel" name="label_9">
<property name="font">
<font>
<pointsize>18</pointsize>
</font>
</property>
<property name="text">
<string>IP Address</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_9">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item alignment="Qt::AlignRight|Qt::AlignVCenter">
<widget class="QLabel" name="ip_address">
<property name="font">
<font>
<pointsize>24</pointsize>
</font>
</property>
<property name="text">
<string>NA</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QTextBrowser" name="test_box"/>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1143</width>
<height>26</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
I would like to achieve something similar to this picture:
except that the top level ("Adress bar", "forms" and "User names...") should be radio buttons.
The idea is that the sublevels should get enabled or disabled depending on the state of the radiobuttons. And the sublevels should be shifted to the right as on the picture.
Can that be done Qt in an elegant way?
I would say a simple QVBoxLayout for the top level and each "sublevel" has a QHBoxLayout with a fixed sized spacer item as the first child and a QVBoxLayout containing the sub options.
Disabling all sub options can then simply be done by disabling the "sublevel" widget.
Just put those sub-items (like "Browsing history", "Favorites", ...) into a separated QWidget and connect that widget's QWidget::setEnabled() slot with the "Adress bar" radio-button's QAbstractButton::toggled() signal.
This is a Qt Designer's .ui file (with working signal-slot connection, try Ctrl+R in Designer) that demonstrates the idea:
<?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>170</width>
<height>178</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="radioButton">
<property name="text">
<string>RadioButton</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_2">
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_3">
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_2">
<property name="text">
<string>RadioButton</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_3">
<property name="text">
<string>RadioButton</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>radioButton</sender>
<signal>toggled(bool)</signal>
<receiver>widget</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>84</x>
<y>17</y>
</hint>
<hint type="destinationlabel">
<x>84</x>
<y>77</y>
</hint>
</hints>
</connection>
</connections>
</ui>
I made a form that looks like this: . The .ui is below.
The QTextEdit on the right is the only widget that has it's horizontal size policy set to Expanding. All the other widgets are either Preferred or Minimum. Yet when I resize the window horizontally, the text edit is the only widget that does not grow. It stays the same size while all the other widgets expand horizontally.
I guess there's something that I don't understand about how all of that works. What do I have to do to make the text edit expand when I resize the window?
.ui file
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWidget</class>
<widget class="QWidget" name="MainWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>634</width>
<height>303</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="4" rowspan="7" colspan="2">
<widget class="QTextEdit" name="textEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>0</height>
</size>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Data written:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLabel" name="readSpeedLabel">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Write speed:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Test Mode:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="5" column="3">
<widget class="QLabel" name="dataWrittenLabel">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Read speed:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="1" colspan="3">
<widget class="QPushButton" name="testModePushButton">
<property name="text">
<string>Select testing mode</string>
</property>
</widget>
</item>
<item row="9" column="2" colspan="2">
<widget class="QPushButton" name="startStopButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Start test</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="3">
<widget class="QPushButton" name="devicePushButton">
<property name="text">
<string>Select device</string>
</property>
</widget>
</item>
<item row="7" column="3">
<widget class="QLabel" name="ETALabel">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLabel" name="writeSpeedLabel">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="7" column="2">
<widget class="QLabel" name="label_11">
<property name="text">
<string>ETA:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="6" column="3">
<widget class="QLabel" name="dataReadLabel">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="6" column="2">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Data Read:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="8" column="0" colspan="4">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Device:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
It is the QLabel items which are messing your layout.
Set the horizontal size policy to Fixed for every QLabel and it works.
Now the answer to why QLabels with Preferred are growing faster than the QTextEdit with an Expanding policy, I do not know. Especially when changing Preferred to Fix solves the problem.
Qt documentation states :
QSizePolicy::Expanding The widget can make use of extra space, so it should get as much space as possible.
QSizePolicy::Preferred The widget can be expanded, but there is no advantage to it being larger than sizeHint().
QSizePolicy::Fixed The QWidget::sizeHint() is the only acceptable alternative, so the widget can never grow or shrink.
Looking at this, it seems that a widget with Preferred would not grow bigger than sizeHint() when next to another widget with Expanding. But in your case labels behave like they have the priority over the text edit.
Note that this does not seem to be the case for QPushButton.
It looks like a bug to me.
So i have a small program i've made with Qt Designer, and for the most part, it's completely fine. But there is one niggling problem;
I have a QLabel, for which the text is sometimes too long, so i want to make the text wrap. This should be a simple task.
Here is what it looks like with no wordwrap
And this is fine. But when the text gets too long, it puts in a horrible scroll bar. I don't want this, so i enable wordwrap. But then this happens:
Which at first i thought was just Qt Designer being crap, so compiled and run hoping it would go away. Sometimes this happens, so i thought it was a reasonable assumption.
It wasn't.
Why the hell is this happening?!
EDIT: enabling word wrap manually in the widget initialiser also causes the same behaviour - so it's not caused by Qt Designer, it's an issue elsewhere. Any help would be greatly appreciated!
Here is the content of 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>705</width>
<height>347</height>
</rect>
</property>
<property name="windowTitle">
<string>Title</string>
</property>
<property name="windowIcon">
<iconset resource="icons.qrc">
<normaloff>:/icons/icons/3/bonus48x48_20.png</normaloff>:/icons/icons/3/bonus48x48_20.png</iconset>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout" columnstretch="0,1,1">
<item row="1" column="0">
<widget class="QLabel" name="label_molecule">
<property name="text">
<string>Molecule:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit_molecule"/>
</item>
<item row="2" column="0" colspan="2">
<widget class="QToolBox" name="toolBox_modelDetails">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="page_isomer">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>373</width>
<height>154</height>
</rect>
</property>
<attribute name="label">
<string>Isomer</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="listWidget_isomers">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_model">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>357</width>
<height>231</height>
</rect>
</property>
<attribute name="label">
<string>Model</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,0">
<item>
<widget class="QListWidget" name="listWidget_models">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<stylestrategy>PreferDefault</stylestrategy>
</font>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_description">
<property name="text">
<string>Howdy!</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_basisSet">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>373</width>
<height>154</height>
</rect>
</property>
<attribute name="label">
<string>Basis Set</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QListWidget" name="listWidget_basisSets">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item row="3" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout_buttons">
<item>
<spacer name="horizontalSpacer_buttons">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_save">
<property name="text">
<string>Save Input File</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_open">
<property name="text">
<string>Open</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="2" rowspan="2">
<widget class="QGroupBox" name="groupBox_MoleculeViewer">
<property name="title">
<string>Molecule</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources>
<include location="icons.qrc"/>
</resources>
<connections/>
</ui>
QLabel in combination with word wrap and Layouts give some funny behaviour.
See https://bugreports.qt.io/browse/QTBUG-37673.
Why are you nesting your widgets (the QLabel and the QListWidget) into a QWidget?
That's why you are getting two scrollbars. One from the QListWidget, because it has more items than can be viewed. And one for the parent QWidget.
You should be using layouts.
This is what you have:
Should be something like this: