Important: Please read the Qt Code of Conduct -

QSplitter not respecting the maximum size of the widget in Qt 5.12.3?

  • Hi all,

    I am trying to troubleshoot an issue with vertical splitter. The splitter contains 2 widgets, a tree view and a custom widget and below is a simplified version of what the code roughly look like.

            mInspectorSplitter = new QSplitter(Qt::Vertical);
            mInspectorSplitter->addWidget(new QTreeView);
            mInspectorSplitter->addWidget(new CustomWidget);
            mInspectorSplitter->setStretchFactor(0, 1);
            mInspectorSplitter->setStretchFactor(1, 0);

    The custom widget has variable maximum size and can change based on user selection in the tree view. Depending on the selection, the custom widget can contain a widget that can expand or a fixed sized widget. When the expandable widget is displayed, the maximum height is 16777215, and when the fixed sized widget is display, the maximum height is 50.

    The problem I am encountering is when the maximum size of the custom widget is modified, the splitter does not automatically adjust for that. Stepping through the code, I can see QSplitterPrivate::doResize() is called whenever the maximum size of custom widget is changed. The size is then determined by this line:

            a[j].sizeHint = qMax(s->getWidgetSize(orient), a[j].minimumSize);

    Here getWidgetSize() would return the value of sizer (seems to be based on where the splitter was moved last) which in my case is greater than the maximumSize() of my custom widget. This caused some undesired behavior that would render an area of nothing and when attempting to move the splitter, it would snap to the maximumSize() of my custom widget correctly.

    Is this a bug or am I missing something?

  • Lifetime Qt Champion


    That looks strange indeed. Can you reproduce that with a minimal compilable example ?
    Did you also check with the latest Qt 5.13 to see if it's still the case ?

Log in to reply