Set fixed size of QMainWindow created in Designer
-
wrote on 19 Apr 2011, 07:38 last edited by
Good day, colleagues!
How can I fix size of QMainWindow created in Designer? Fix size means that I want to see main window as I created it in Designer without ability to resize.
I've tried this:
@ui->setupUi(this);
centralWidget()->layout()->setSizeConstraint(QLayout::SetFixedSize);@But got segfault.
-
wrote on 19 Apr 2011, 07:59 last edited by
To fix the size of the main window itself just call:
@setFixedSize( myDesiredSize );@
It's a member of QWidget which of course QMainWIndow inherits.
-
wrote on 19 Apr 2011, 08:01 last edited by
try this:
this->setFixedSize(500,500);edit:
didnt noticed that you allready gave the answer ZapB. :) -
wrote on 19 Apr 2011, 08:45 last edited by
Thank you very much, this works, but is there any way to automatically get myDesiredSize from Designer?
With current solution I should manually copy width and height values from Designer MainWindow geometry.
-
wrote on 19 Apr 2011, 08:58 last edited by
Did you try to set both maximum and minimum size in Designer? Right click on your main form and select Size Constraints -> Set Minimum Size and then Size Constraints -> Set Maximum Size.
-
wrote on 19 Apr 2011, 09:00 last edited by
try this:
@ this->setFixedSize(this->geometry().width(),this->geometry().height());@edit:
"this" is not needed. -
wrote on 19 Apr 2011, 09:05 last edited by
Thank you, both solutions work, but to my mind, second is more elegant.
-
wrote on 19 Apr 2011, 09:14 last edited by
You can also get the preferred size from the sizeHint() functionality and use that as the argument in the setFixedSize() call. That way if your central widget ever changes your app will automatically calculate the new preferred size - as long as the central widget implements a sensible sizeHint of course.
-
wrote on 19 Apr 2011, 09:47 last edited by
[quote author="vinb" date="1303204074"]@marko-a,
Its possible to set your maxsize the same as your minsize, but why do that if you have a nice function (setFixedSize) for it to do the job?[/quote]True, but the original question was:
[quote author="usamytch" date="1303198694"]
How can I fix size of QMainWindow created in Designer? Fix size means that I want to see main window as I created it in Designer without ability to resize.
[/quote]Thus if you wish to solve problem by using only Designer you can do so by setting minimum & maximum size constraints.
Cheers!
-
wrote on 19 Apr 2011, 09:53 last edited by
They are both valid solutions. In fact they amount to the same thing since that is all that the setFixedSize() function does anyway.
1/11