C++ – QSplitter: How to make second column smaller

cqsplitterqt-creator

In QtCreator I created a QSplitter which separates vertically a QTreeWidget from a vertical layout with many things on the right.

I would like that this second column by default takes the minimum space it needs to maximise the first one.

I tried setting sizes and vertical policy of the splitter as expanding but surely I'm not doing it right. How can I set this exactly?

Best Answer

You can set this in code with QSplitter::setStretchFactor(int index, int stretch).

You would set the first column to have a stretch of 1 and the second 0.

splitter->setStretchFactor(0, 1);
splitter->setStretchFactor(1, 0);