@Dong
Finally got it solved. Your last reply got me to set up a simple MainWindow to experiment.
Here's the code for anyone who's interested.
Any improvements are welcome.
Remember that this shows and hides a bottom widget where the top and bottom widgets are inside a splitter.
Note: splitterSizes is a QList<int>
In constructor:
// hide the bottom widget
int topWidgetHeight = ui->topWidget->sizeHint().height(); // top widget height
bottomWidgetHeight = 100 + ui->splitter->handleWidth(); // I set the bottomWidgetHeight
splitterSizes << topWidgetHeight << 0;
ui->splitter->setSizes(splitterSizes);
ui->splitter->handle(1)->setUpdatesEnabled(false); // hides the handle - it can't repaint - setHidden(true) doesn't work
bottomWidgetHidden = true;
// hide the bottom widget
int topWidgetHeight = ui->topWidget->sizeHint().height(); // top widget height
bottomWidgetHeight = 100 + ui->splitter->handleWidth(); // I set the bottomWidgetHeight
splitterSizes << topWidgetHeight << 0;
ui->splitter->setSizes(splitterSizes);
ui->splitter->handle(1)->setUpdatesEnabled(false); // hides the handle - it can't repaint - setHidden(true) doesn't work
bottomWidgetHidden = true;
To copy to clipboard, switch view to plain text mode
on_button_Click() method:
void MainWindow::on_ButtonClicked()
{
if (bottomWidgetHidden)
{
// show bottom widget
int topWidgetHeight = ui->topWidget->height();
mainWindowSize = this->size();
splitterSizes.clear();
splitterSizes << topWidgetHeight << bottomWidgetHeight;
ui->splitter->setSizes(splitterSizes);
ui->splitter->handle(1)->setUpdatesEnabled(true); // shows the handle
this->resize(mainWindowSize.width(), mainWindowSize.height() + bottomWidgetHeight);
}
else
{
// hide bottom widget
// get sizes/heights
mainWindowSize = this->size();
int topWidgetHeight = ui->topWidget->height();
bottomWidgetHeight = ui->bottomWidget->height();
// set the widget heights - this maintains the size of the top widget
splitterSizes.clear();
splitterSizes << topWidgetHeight << 0;
ui->splitter->setSizes(splitterSizes);
ui->splitter->handle(1)->setUpdatesEnabled(false); // hides the handle - it can't repaint - setHidden(true) doesn't work
this->resize(mainWindowSize.width(), mainWindowSize.height() - bottomWidgetHeight);
}
bottomWidgetHidden = !bottomWidgetHidden;
}
void MainWindow::on_ButtonClicked()
{
if (bottomWidgetHidden)
{
// show bottom widget
int topWidgetHeight = ui->topWidget->height();
mainWindowSize = this->size();
splitterSizes.clear();
splitterSizes << topWidgetHeight << bottomWidgetHeight;
ui->splitter->setSizes(splitterSizes);
ui->splitter->handle(1)->setUpdatesEnabled(true); // shows the handle
this->resize(mainWindowSize.width(), mainWindowSize.height() + bottomWidgetHeight);
}
else
{
// hide bottom widget
// get sizes/heights
mainWindowSize = this->size();
int topWidgetHeight = ui->topWidget->height();
bottomWidgetHeight = ui->bottomWidget->height();
// set the widget heights - this maintains the size of the top widget
splitterSizes.clear();
splitterSizes << topWidgetHeight << 0;
ui->splitter->setSizes(splitterSizes);
ui->splitter->handle(1)->setUpdatesEnabled(false); // hides the handle - it can't repaint - setHidden(true) doesn't work
this->resize(mainWindowSize.width(), mainWindowSize.height() - bottomWidgetHeight);
}
bottomWidgetHidden = !bottomWidgetHidden;
}
To copy to clipboard, switch view to plain text mode
Cheers
Jeff
Bookmarks