QToolbox changes width
-
Hi,
I've got an issue where a toolbox width resizes depending on which page is selected - as can be seen in the following.The designer code is below, and loading that into Designer and previewing you can see the issue. What I'd like is that the toolbox picks it's widest page's preferred size and uses that as it's own, so changing pages doesn't move it*. I'd rather not have to see min or max sizes as that then breaks if I add or remove stuff and have to go through each one to check.
<?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>462</width> <height>519</height> </rect> </property> <property name="windowTitle"> <string>Form</string> </property> <layout class="QHBoxLayout" name="horizontalLayout"> <item> <widget class="QGroupBox" name="leftGroup"> <property name="title"> <string>GroupBox</string> </property> <layout class="QVBoxLayout" name="verticalLayout_2"> <item> <layout class="QHBoxLayout" name="horizontalLayout_2"> <item> <widget class="QLabel" name="label"> <property name="text"> <string>TextLabel</string> </property> </widget> </item> <item> <widget class="QLineEdit" name="lineEdit_2"/> </item> </layout> </item> <item> <widget class="QSlider" name="horizontalSlider"> <property name="orientation"> <enum>Qt::Orientation::Horizontal</enum> </property> </widget> </item> <item> <widget class="QToolBox" name="toolBox"> <property name="currentIndex"> <number>1</number> </property> <widget class="QWidget" name="page"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>199</width> <height>353</height> </rect> </property> <attribute name="label"> <string>Page 1</string> </attribute> </widget> <widget class="QWidget" name="page_2"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>302</width> <height>347</height> </rect> </property> <attribute name="label"> <string>Page 2</string> </attribute> <layout class="QVBoxLayout" name="verticalLayout_3"> <item> <widget class="QLabel" name="label_2"> <property name="text"> <string>This is a long label that I'm putting here to see the size</string> </property> </widget> </item> <item> <widget class="QLineEdit" name="lineEdit"/> </item> </layout> </widget> </widget> </item> </layout> </widget> </item> <item> <widget class="QWidget" name="widgetRight" native="true"> <layout class="QVBoxLayout" name="verticalLayout"> <item> <widget class="QGroupBox" name="groupBox"> <property name="title"> <string>GroupBox</string> </property> <layout class="QHBoxLayout" name="horizontalLayout_4"> <item> <widget class="QToolBox" name="toolBox_2"> <property name="currentIndex"> <number>0</number> </property> <widget class="QWidget" name="page_3"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>78</width> <height>143</height> </rect> </property> <attribute name="label"> <string>Page 1</string> </attribute> </widget> <widget class="QWidget" name="page_4"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>78</width> <height>143</height> </rect> </property> <attribute name="label"> <string>Page 2</string> </attribute> </widget> </widget> </item> </layout> </widget> </item> <item> <widget class="QGroupBox" name="groupBox_2"> <property name="title"> <string>GroupBox</string> </property> <layout class="QHBoxLayout" name="horizontalLayout_3"> <item> <widget class="QToolBox" name="toolBox_3"> <property name="currentIndex"> <number>0</number> </property> <widget class="QWidget" name="page_5"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>78</width> <height>142</height> </rect> </property> <attribute name="label"> <string>Page 1</string> </attribute> </widget> <widget class="QWidget" name="page_6"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>78</width> <height>142</height> </rect> </property> <attribute name="label"> <string>Page 2</string> </attribute> </widget> </widget> </item> </layout> </widget> </item> </layout> </widget> </item> </layout> </widget> <resources/> <connections/> </ui>
-
@Musmuris said in QToolbox changes width:
<layout class="QHBoxLayout" name="horizontalLayout">
Try to apply a layout stretch of 3,1 to the first hlayout,
this way the first toolbox will have 2/3 of the window width and the second one 1/3
Of course you can set the stetch ratio you want 4/1 or any other. -
@mpergand Thanks - this is what I've done but it's not ideal as there two boxes have different "natural" widths as it were, and forcing a proportional size on them is a bit of a kludge. Better than not - but you'd like to think it it shouldn't be needed.