Problem size policy in QStackedWidget
-
@JonB said in Problem size policy in QStackedWidget:
Where in the second screenshot is there "big space at top and bottom"? I see space above & below Test running... (is that your "A QGroupBox with vertical size policy : Fixed"?), but not at the top/bottom of the QStackedWidget itself, which is what you claimed?
Yes there is space above and below "Test running ...". This is a QStackedWidget with another page containing a QLabel.
-
Are you doing any modification to that widget in the constructor ?
-
I would add a stretch factor of two to the QTableWidget so that it should take more place naturally.
-
@SGaist said in Problem size policy in QStackedWidget:
I would add a stretch factor of two to the QTableWidget so that it should take more place naturally.
It has no effect. This is weird, when i add a stretch factor of 2 to the QTableWidget and a stretch factor of 1 to the QStackedWidget in QtDesigner, i have the same effect that in the application. I don't think there is a link but i would to mention it.
-
Without sharing your application, can you provide a minimal compile example that shows that behaviour ?
-
Here is an example :
main.cpp :#include <QApplication> #include <QWidget> #include "ui_test.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget parent; Ui_Form form; form.setupUi(&parent); QObject::connect(form.switchButton, &QPushButton::clicked, [=]() { form.testStackedWidget->setCurrentIndex(form.testStackedWidget->currentIndex() == 0 ? 1 : 0); }); parent.show(); return app.exec(); }
And test.ui :
<?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>306</width> <height>517</height> </rect> </property> <property name="windowTitle"> <string>Form</string> </property> <layout class="QVBoxLayout" name="verticalLayout"> <property name="margin"> <number>0</number> </property> <item> <widget class="QStackedWidget" name="mainStackedWidget"> <property name="currentIndex"> <number>0</number> </property> <widget class="QWidget" name="page"> <layout class="QVBoxLayout" name="verticalLayout_2"> <item> <widget class="QStackedWidget" name="testStackedWidget"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="currentIndex"> <number>0</number> </property> <widget class="QWidget" name="page_3"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <layout class="QVBoxLayout" name="verticalLayout_3"> <item> <widget class="QLabel" name="label"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="text"> <string><html><head/><body><p align="center">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ut enim justo. Quisque vitae massa pellentesque, tristique arcu id, elementum urna. Proin sit amet lectus quam. Maecenas ullamcorper elit eget neque volutpat scelerisque. In hac habitasse platea dictumst. Donec convallis dui a vehicula feugiat.</p></body></html></string> </property> <property name="wordWrap"> <bool>true</bool> </property> </widget> </item> </layout> </widget> <widget class="QWidget" name="page_4"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <layout class="QVBoxLayout" name="verticalLayout_4"> <item> <widget class="QLabel" name="label_2"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="text"> <string>Test running...</string> </property> <property name="wordWrap"> <bool>true</bool> </property> </widget> </item> </layout> </widget> </widget> </item> <item> <widget class="QTableWidget" name="tableWidget"> <property name="sizePolicy"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <horstretch>0</horstretch> <verstretch>1</verstretch> </sizepolicy> </property> <property name="showGrid"> <bool>true</bool> </property> <attribute name="horizontalHeaderDefaultSectionSize"> <number>80</number> </attribute> <attribute name="horizontalHeaderStretchLastSection"> <bool>true</bool> </attribute> <column> <property name="text"> <string>A</string> </property> </column> <column> <property name="text"> <string>B</string> </property> </column> <column> <property name="text"> <string>C</string> </property> </column> </widget> </item> <item> <widget class="QPushButton" name="switchButton"> <property name="text"> <string>Switch</string> </property> </widget> </item> </layout> </widget> <widget class="QWidget" name="page_2"/> </widget> </item> </layout> </widget> <resources/> <connections/> </ui>
-
You're correct and that's a good question. What version of Designer are you using ?