Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-72571

QSplitter don't resize child widgets as expected in some cases

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.7.0, 5.12
    • Widgets: Layout
    • None

    Description

      Precondition:

      1 QMainWidget contains a QSplitter, which separates the two widgets. On the left there is a QLabel, on the right there is a QComboBox. QComboBox contains an element with very long text.

      2 You must set the minimum size for a QMainWidget object. It should be smaller than the hintSize of the QComboBox object, for example 200, 100. And resize window to this size.

      Steps for reproducing:

      1 Run app
      2 Catch splitter and move it to the right, to the left.

      Actual result:

      The widget on the right side dramatically increases in size (most likely takes the hintSize of the QComboBox object), jumps to the left, to the right. The widget on the left side is entirely or partially outside the window.

      Expected results:

      a. the splitter does not allow resizing widgets
      b. the widget on the right smoothly resizes

      Important note: when you resize QMainWidget object (you need to move the window borders), child widgets are resized as expected.

      Example:

       

      #include <QApplication>
      #include <QMainWindow>
      #include <QSplitter>
      #include <QVBoxLayout>
      #include <QLabel>
      #include <QComboBox>
      
      QWidget* createLeftWidget()
      {
          QWidget *widget = new QWidget;
          widget->setLayout(new QVBoxLayout);
          widget->layout()->addWidget(new QLabel("Left widget"));
          return widget;
      }
      
      QWidget* createRightWidget()
      {
          QWidget *widget = new QWidget;
          widget->setLayout(new QVBoxLayout);
          QComboBox *comboBox = new QComboBox;
          comboBox->addItem("1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111");
          widget->layout()->addWidget(comboBox);
          return widget;
      }
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          QMainWindow mainWindow;
          mainWindow.setMinimumSize(200, 100);
          mainWindow.resize(200, 100);
      
          QSplitter *splitter = new QSplitter;
          splitter->setChildrenCollapsible(false);
      
          mainWindow.setCentralWidget(splitter);
      
          splitter->addWidget(createLeftWidget());
          splitter->addWidget(createRightWidget());
      
          mainWindow.show();
      
          return a.exec();
      }
      

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            ejector Denis Rodkin
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes