PDA

View Full Version : How to resize again after setFixedSize() ?



chiaminhsu
22nd January 2013, 16:05
Hi,
I have a project to lock the window size while doing something.
When the job is finished, the window can be expanded again.

I try to
setFixedSize() is called first, and then
setSizePolicy() is called to set the window resizable again.

setFixedSize() works, however, setSizePolicy() can not enable
resizing function again.

Is resizing after setFixedSize() possible ?

void MainWindow::startAct()
{
this->setFixedSize(this->size());
QTimer::singleShot(60000, this, SLOT(endAct()));
}
void MainWindow::endAct()
{
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); // resizable again
}

wysota
22nd January 2013, 16:54
I'd suggest to use QLayout::setSizeConstraint() rather than what you are doing.

chiaminhsu
22nd January 2013, 19:50
Thank your. However, QLayout is a virtual class.
My MainWindow is a simple view window.
Should I use QBoxLayout or other ?

wysota
22nd January 2013, 19:59
Your MainWindow has a layout installed that can be retrieved with layout(). Call setSizeConstraint() on it asking for fixed size and then back when you want to remove the constraint.

chiaminhsu
23rd January 2013, 04:27
sorry, I rewrite it as the following code. However,
the window disapeared running setSizeConstraint.
What's wrong with it ?

QLayout * layout = this->layout(); // this MainWindow
layout->setSizeConstraint(QLayout::SetFixedSize);

* Infact, it's an Qt example called as Tablet.
* The main window contains a canvas widget only.
MainWindow::MainWindow(TabletCanvas *canvas) {
..
setCentralWidget(canvas);
}

wysota
23rd January 2013, 10:57
It is probably because of a proper size policy and size hint of the central widget of the window not being set correctly. The size policy probably allows the widget to be shrunk to 0.