How to keep the window maximized?
I want to keep the window maximized.
It's ok to minimizing it.
I tried as below:
void MainWindow::resizeEvent(QResizeEvent* e)
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.
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.
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.
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?
thanx for explaining finely:)
then,I'll use 1024×768.
it's right but now solved:)
OK, so you've discovered
mainWindow.setMinimumSize(1024, 768);, right?
yes,I'll use it or setFixedSize(1024,768)
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. :)
hmm,my gui application may be suitable if its size is restricted.
I'll try both and then decide which to use:)