First I want to thank you for your time, I’m new to Qt and I hope I won’t bother you but I have a simple question and I hope I can get a simple answer.
The circumstances are the following:
I made a QmainWindow
That has 1+3 widgets:
// a main widget
QWidget *centralWidget;
//with a main Layout
QGridLayout *mainLayout;
//a top Widget (child of centralWidget)
QWidget *topWidget;
//with a top Layout
QGridLayout *topLayout;
//[…]more childWidgets of topWidget,
//including a moreButton that when I press it expands middle Widget
//a middle Widget (child of centralWidget)
QWidget *middleWidget;
//with a middle Layout
QVBoxLayout *middleLayout;
//[…]more childWidgets of middleWidget;
//a bottom Widget (child of centralWidget)
QWidget * bottom Widget;
//with a bottom Layout
QHBoxLayout * bottom Layout;
//[…]more childWidgets of bottom Widget;
So I hide the middleWidget->hide() in the constructor;
Then I resize the window so it will start “compressedâ€
size = size.expandedTo(mainLayout->minimumSize());
resize(size);
QSize size(0, 0);
size = size.expandedTo(mainLayout->minimumSize());
resize(size);
To copy to clipboard, switch view to plain text mode
I connect the more button
connect(moreButton, SIGNAL(toggled(bool)),
middleWidget, SLOT(setVisible(bool)));
connect(moreButton, SIGNAL(toggled(bool)),
middleWidget, SLOT(setVisible(bool)));
To copy to clipboard, switch view to plain text mode
and it works well but the problem is that after I made it visible and I hide again the middleWidget the window doesn’t compress back, the MainLayout just covers the empty space left by the middleWidget.
I even made a SLOT makeSmall that I connected to the moreButton so that it will
compress again but id doesn't change the size.
size = size.expandedTo(mainLayout->minimumSize());
this->resize(size);
QSize size(0, 0);
size = size.expandedTo(mainLayout->minimumSize());
this->resize(size);
To copy to clipboard, switch view to plain text mode
If I make the middleLayout visible again the window will keep the same size.
I want to make the window shrink when I hide the widget but I don't know how how to do it every time I hide the widget (as I sad it compresses at start but afterwards it remains big).
Sorry if the post is a bit confusing.
Bookmarks