How to keep the window maximized?
-
Hi.
I want to keep the window maximized.
It's ok to minimizing it.
I tried as below:void MainWindow::resizeEvent(QResizeEvent* e)
{
showMaximized();
}but this isn't smart and can't be minimized:(
Is there any good way? -
@rick_nakano You could check when it is being resized if it is minimized or not, if not, then force maximize it, if it is then ignore the resize.
Something like:
if (!isMinimized()) showMaximized();
Haven't tested that but it seems like it would work.
Another idea is instead of using maximize, figure out what the max size would be and force that geometry when the window is not minimized.
Also, I don't know what you're developing but I find apps that try to control my preferences (like sizing) to be incredibly annoying and won't use them. So it's not a great idea to restrict your users unless you have a good reason.
-
@ambershark
thanks:)
I decided not to restrict the size as you said. -
@rick_nakano Good call, most users would really hate that. Qt is great at sizing widgets to fit and you can always set a minimum size that your GUI looks good with. I tend to use 800x600 or 1000x700 as my minimum sizes. Most people have at least 1024x768 resolutions now-a-days so I figure that should be fine. Gives me room to work with the GUI design too.
-
@rick_nakano
You want to allow the window to be minimized or maximized (e.g. via the window buttons), but not to be drag-resized to anything else, is that right? -
@ambershark
thanx for explaining finely:)
then,I'll use 1024×768. -
@JNBarchan
it's right but now solved:) -
@rick_nakano
OK, so you've discoveredmainWindow.setMinimumSize(1024, 768);
, right? -
@JNBarchan
yes,I'll use it or setFixedSize(1024,768) -
@rick_nakano No you want to use setMinimumSize like @JNBarchan suggested. Setting a fixed size forces the widget to that size only.
I would assume you want your gui resizeable, if not then set a fixed size, if so then use the minimum so you always have at least that size. :)
-
@ambershark
hmm,my gui application may be suitable if its size is restricted.
I'll try both and then decide which to use:)