How to resize QSplitter automatically according to QWidget
-
I have tried something like below:
QWidget *wid = new QWidget;
QSplitter *hSplitter = new QSplitter(Qt::Horizontal, wid);
QTabWidget *tWid = new QTabWidget;
QTextBrowser *tBrowser = new QTextBrowser;hSplitter->insertWidget(0, tWid);
hSplitter->insertWidget(1, tBrowser);
hSplitter->setHandledWidth(0);wid->show();
what I want is that QSplitter should automatically resize according to QWidget, when the window is minimized or maximized
but its not happening
QSplitter size is fixed, it is not resizing.
Please suggest how to achieve it.
-
You have to insert the splitter in a layout
QWidget *wid = new QWidget; QSplitter *hSplitter = new QSplitter(Qt::Horizontal, wid); QHBoxLayout* widLay=new QHBoxLayout(wid); hSplitter->addWidget(hSplitter); // all the rest
Btw, make sure you are not leaking memory in
wid
, give it a parent or handle the delete -
I tried what you suggested with a little change
QWidget *wid = new QWidget; QSplitter *hSplitter = new QSplitter(Qt::Horizontal, wid); QHBoxLayout* widLay=new QHBoxLayout(wid); widLay->addWidget(hSplitter);
This works fine when I run the code, and show the QWidget (here wid) from the menu.
But when I close it and again show the QWidget from the menu, widLay is not covering the entire widget, only some part in the top left corner, and rest widget is blank.
And I also observe something on command line:
setGeometry: UInable to set geometry 540x241+1366+22 on QWidgetWindow........Please suggest how to solve this.
-
Hi,
Out of curiosity, why use a QSplitter at all since you don't use it of any resizing operation ?