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

22nd January 2013, 15:05
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()
QTimer::singleShot(60000, this, SLOT(endAct()));
void MainWindow::endAct()
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); // resizable again

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

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

22nd January 2013, 18: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.

23rd January 2013, 03: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

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

23rd January 2013, 09: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.