QSplitter: Restrict movement after reaching a certain point
-
Hi, i have a problem, hope for your help. I have treeView and label above it (with vertical layout) on the left side and i have stackedWidget on the right side with tabWidget and label on it. There is a splitter between them. I want the splitter to move when the tree is resized, for example, only to the middle of the window:
Thus, if I move the slitter from left to right, it will only reach the middle. How to do it?
I tried to set the maximum width for the treeView widget, but I get the following situation: the tree widget reaches its maximum width, and the splitter can be further moved to the right. It turns out empty space between widgets:
-
Don't set the maximum width of the treeView. You need to set the splitter's direct child widget.
Convert your vertical layout to a QWidget (in designer that's called "morph into"), and set the maximum width of it.[Updated]
Ah, I just remember a way that can set the maximum size of a layout.
You still need to set the splitter's direct child, but you can do that by setting the maximum width of the treeView.
Then callsetSizeConstraint(QLayout::SetMaximumSize)
to the vertical layout, or set itslayoutSizeConstraint
in the designer.
SetMinAndMaxSize
should also work.But in my opinion the first method is still the better way.
-
I forgot to mention - this layout is installed in the QWidget, i.e. splitter separates two widgets (QWidget, that contains vertical layout, that contains QLabel and QTreeView and QStackWidget).
I figured out my mistake - I was setting the maximum width (setMaximumWidth
) for the QTreeView object, not for the widget added to the splitter (QWidget).
@Bonnie thank you!