How to get minimum size Mainframe?
-
wrote on 16 May 2024, 08:14 last edited by
Hi Forum,
I want a mainframe that can not get smaller than the collection of the minimum size widgets it contains.
Is there a general setting or way how to achieve this, instead of writing my own resize event for the mainframe? Or ist that the only way?
Could not find good info about this topic.
Recommendations for other methods or ideas are welcome. -
Hi Forum,
I want a mainframe that can not get smaller than the collection of the minimum size widgets it contains.
Is there a general setting or way how to achieve this, instead of writing my own resize event for the mainframe? Or ist that the only way?
Could not find good info about this topic.
Recommendations for other methods or ideas are welcome.wrote on 16 May 2024, 08:40 last edited by JonB@SiGa
I always fight with Qt layouts/policies too, even after all this time! Have you tried QSizePolicy::Maximum? You still have to calculatesizeHint()
yourself dynamically to the bounding rectangle of the widget contents, I believe. Or there is setMaximumSize(). Whether this is any simpler than trappingresize
event I don't know. -
@SiGa
I always fight with Qt layouts/policies too, even after all this time! Have you tried QSizePolicy::Maximum? You still have to calculatesizeHint()
yourself dynamically to the bounding rectangle of the widget contents, I believe. Or there is setMaximumSize(). Whether this is any simpler than trappingresize
event I don't know.wrote on 16 May 2024, 09:21 last edited by@JonB
Glad to hear that also experts struggle at some things , guess we are still human ;)I need to provide an example for better understanding.
I have my GUI program which has a default size, that I assume the user will be happy with.
Now the user changes the size of the mainframe(i.e. the topmost frame|widget) by dragging the corner with the mouse.
He can drag it so small, that elements in the mainframe start overlapping and it turns unusable.
I want to prevent dragging it to an unusable size. -
wrote on 16 May 2024, 09:37 last edited by mpergand
Can you provide more infos (code, screenshot)
because that's not what I observe.If I do:
MainWindow mw; mw.show(); mw.resize(mw.minimumSize());
The window cannot be resized smaller by the user or by code (seems logical).
-
Can you provide more infos (code, screenshot)
because that's not what I observe.If I do:
MainWindow mw; mw.show(); mw.resize(mw.minimumSize());
The window cannot be resized smaller by the user or by code (seems logical).
-
wrote on 17 May 2024, 06:45 last edited by
I'm not sure what you are doing. If the mainframe has a layout and all widget are inside nested layout, you cannot go below the minimum size of each individual widget and nothing will overlap. So, somehow you have used the layouts wrong. Without any code/.ui files it is really hard to diagnose the problem.
-
wrote on 23 Jul 2024, 09:34 last edited by SiGa
I can not reproduce my problem anymore, and it behaves as all of you described.
Thanks for the feedback.
I will just mark JonB's answer as the correct one, since there is no correct answer. -
-
I can not reproduce my problem anymore, and it behaves as all of you described.
Thanks for the feedback.
I will just mark JonB's answer as the correct one, since there is no correct answer.wrote on 23 Jul 2024, 12:04 last edited byAs @SimonSchroeder said above, if you were using layouts properly, there's almost no way that things overlap, when resizing the main widget. Only free floating widgets, which are not part of any layout might do.