Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a QSplitter with layouts

Tags:

qt

In my app I have a treeview at the top with some buttons above it related to the treeview. Below this I have a table view, again with some buttons related to it. I have a QVBoxLayout top and bottom.

Please see the screen show.

What I'd like to do is be able to adjust the size of the top and bottom in the way that a QPlitter allows you to do. But ... a QSplitter only accepts widgets, not layouts.

I'd like to be able to drag where the red line is in the screen shot.

I'm creating the layout in C++ not in the designer.

Is there a way to do this?

Layout showing where I'd like a splitter

like image 856
Michael Vincent Avatar asked Apr 02 '15 10:04

Michael Vincent


People also ask

What is a QSplitter?

Detailed Description. A splitter lets the user control the size of child widgets by dragging the boundary between them. Any number of widgets may be controlled by a single splitter. The typical use of a QSplitter is to create several widgets and add them using insertWidget() or addWidget().

What is QVBoxLayout?

QVBoxLayout organizes your widgets vertically in a window. Instead of organizing all the widgets yourself (specifying the geographic location), you can let PyQt take care of it. Every new widget you add with . addWidget() , is added vertically. Basically you get a vertical list of your widgets.


1 Answers

Wrap your widgets inside another widget, like so:

Splitter
 ├──Top Widget
 │   └──Layout 1
 │       ├──Button 1
 │       ├──Button 2
 │       └──Text Area 1
 └──Bottom Widget
     └──Layout 2
         ├──Button 3
         ├──Button 4
         └──Text Area 2

Example:

QWidget *topWidget = new QWidget;
topWidget->setLayout(layout1);
...
splitter->addWidget(topWidget);
splitter->addWidget(bottomWidget);
like image 134
svlasov Avatar answered Sep 28 '22 16:09

svlasov