How to allow QWidget to expand to the whole tab in QTabWidget?

I've never been too big when it comes to layouts and size policies, so this is probably the simple answer, but here it goes.

When I add a new tab to QTabWIdget and install the widget in QSplitter, the splitter will use all the space provided. However, when I put a QSplitter in a QWidget and add a tab using a QWidget, it will not use the pressure space - only that the size of the separator.

I would like to stay away from QLayout, since I have all the necessary widgets in the splitters. Just getting my QWidget to use all the space in the tab (which should allow QSplitter to use all the space in the QWIdget) is what I need.

I built a sample below showing the comparison as well as the result. A short short question - how can I get script one (in "Tab One") so that it looks like script two ("Tab Two") and still use the parent QWidget for Spliiter?

ui->setupUi(this); QTabWidget* pTab = new QTabWidget(this); this->setCentralWidget(pTab); //Splitter belongs to a QWidget, which belongs to the Tab. Does not use all space QWidget* pWidget = new QWidget(this); QSplitter* pSplitter = new QSplitter(pWidget); QListWidget* pList = new QListWidget(this); QListWidget* pList2 = new QListWidget(this); pSplitter->addWidget(pList); pSplitter->addWidget(pList2); pTab->addTab(pWidget, "Tab One"); //Splitter belongs to the Tab. Uses all space QListWidget* pList3 = new QListWidget(this); QListWidget* pList4 = new QListWidget(this); QSplitter* pSplitter2 = new QSplitter(this); pSplitter2->addWidget(pList3); pSplitter2->addWidget(pList4); pTab->addTab(pSplitter2, "Tab Two"); 

End result

+4
source share
1 answer

Change this:

 QWidget* pWidget = new QWidget(this); QSplitter* pSplitter = new QSplitter(pWidget); 

For this:

 QWidget* pWidget = new QWidget(this); QVBoxLayout* layout = new QVBoxLayout(pWidget); QSplitter* pSplitter = new QSplitter(pWidget); layout->addWidget(pSplitter); 
+5
source

All Articles