Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem size policy in QStackedWidget
QtWS25 Last Chance

Problem size policy in QStackedWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
sizepolicyqstackedwidget
14 Posts 3 Posters 5.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Loic B.
    wrote on 31 Aug 2018, 09:40 last edited by
    #5

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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 31 Aug 2018, 22:06 last edited by
      #6

      Are you doing any modification to that widget in the constructor ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Loic B.
        wrote on 3 Sept 2018, 07:31 last edited by
        #7

        Hello,

        @SGaist said in Problem size policy in QStackedWidget:

        Are you doing any modification to that widget in the constructor ?

        No, not in this page.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 3 Sept 2018, 20:52 last edited by
          #8

          I would add a stretch factor of two to the QTableWidget so that it should take more place naturally.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • L Offline
            L Offline
            Loic B.
            wrote on 4 Sept 2018, 10:05 last edited by
            #9

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

            1 Reply Last reply
            0
            • L Offline
              L Offline
              Loic B.
              wrote on 7 Sept 2018, 09:08 last edited by
              #10

              The only solution that i see is too put two labels and hide/show them for change the text.
              No others ideas ?

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 7 Sept 2018, 22:01 last edited by
                #11

                Without sharing your application, can you provide a minimal compile example that shows that behaviour ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  Loic B.
                  wrote on 10 Sept 2018, 09:20 last edited by Loic B. 9 Oct 2018, 09:32
                  #12

                  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>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;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.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</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>
                  
                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    Loic B.
                    wrote on 10 Sept 2018, 10:08 last edited by
                    #13

                    I think this is normal. The text in the first page of testStackedWidget takes more lines so the global height is take from here. However, why Qt Designer don't show the same behavior ?

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 16 Sept 2018, 20:09 last edited by
                      #14

                      You're correct and that's a good question. What version of Designer are you using ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      14/14

                      16 Sept 2018, 20:09

                      • Login

                      • Login or register to search.
                      14 out of 14
                      • First post
                        14/14
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved