PDA

View Full Version : How to maximize QSplitter in a QWidget



tkm
28th December 2010, 06:47
I've a QSplitter inside a QWidget. Within the QSplitter, I've added a QTreeView and a QListView. Both the view widgets have not been populated yet. The QWidget is set to show maximized.

My question is how to show the QSplitter to be maximized too? Currently, the QSplitter's height is taking up only a portion of the QWidget's area (about a quarter); it's height is not fully stretched to occupy the QWidget. The QSplitter's width, however, has been fully stretched to fill the QWidget.

Other than hard coding the fixed height to the QSplitter, is there any other way to achieve this? Since different computers may have different resolution, I don't want to set a hard coded height to the QSplitter.

high_flyer
28th December 2010, 09:17
What is the point of using a splitter if you want it "maximized"?
Its sounds more like you need a QStackedWidget.

tkm
28th December 2010, 09:55
What is the point of using a splitter if you want it "maximized"?
Its sounds more like you need a QStackedWidget.

I am trying to replicate the Windows Explorer view where there's a treeview on the left side of the splitter and a listview on the right. The splitter in the explorer is fully stretched to the bottom of the window so that's my aim.

nroberts
28th December 2010, 17:14
I'm just guessing, but it sounds to me like you haven't put something in a layout that needs to be. Is the widget that your splitter is governing the central widget of the window or has it been added? Did you add it to a layout?

tkm
29th December 2010, 04:07
I'm just guessing, but it sounds to me like you haven't put something in a layout that needs to be. Is the widget that your splitter is governing the central widget of the window or has it been added? Did you add it to a layout?

My splitter has two widgets. Both should be the central. The splitter is added to a layout.
My code as below: (Do note that the code exists in the constructor of a class inheriting a QWidget)

splitter = new QSplitter(Qt::Horizontal);

treeItem = new QTreeView;
listItem = new QListView;
QList<int> sizes;
sizes.append(200);
sizes.append(600);

splitter->addWidget(treeItem);
splitter->addWidget(listItem);
splitter->setSizes(sizes);
splitter->setStretchFactor(0, 1);
splitter->setStretchFactor(1, 1);

QVBoxLayout *layoutMain = new QVBoxLayout;
layoutMain->setContentsMargins(0, 0, 0, 0);
layoutMain->addWidget(splitter);
layoutMain->addStretch();
setLayout(layoutMain);
showMaximized();