Search code examples
qtqsplitter

QSplitter with one fixed size widget and one variable size widget?


Is it possible to have a QSplitter which has one widget of a fixed size and the other with a variable size?

This code sets things right, but when the window is resized the splitter changes proportionally to the initial widgets sizes:

vSplitter = new QSplitter(Qt::Vertical, this);
vSplitter->addWidget(widget1);
vSplitter->addWidget(widget2);
QList<int> heights;
heights.push_back(550);
heights.push_back(1000);
vSplitter->setSizes(heights);

setCentralWidget(vSplitter);

Thank you.


Solution

  • Try this one:

    QSplitter::setStretchFactor ( int index, int stretch )

    Just set the stretch factor of the part you want to remain fixed size to 0 and set it to 1 on the other widget.

    When resize the entire window, the widget with the stretch factor 0 won't resize.