I am trying to make it so a GUI I built in Qt will re size to any users window. I know this is traditionally done using a layout manager, however none of the layout managers suit my needs. Every manager seems to create disproportional widgets. Is there any way to just make of my widgets and certain percent of the screen. I want to maintain the current relative positioning of my widgets and just have them re size as the screen re sizes by the same factor.
Asked
Active
Viewed 106 times
0
-
You can implement your own layout that takes a snapshot of the initial layout and then resizes proportionally. Or you can tell us what layout you wish, and we can show you how to implement it using existing layouts, if possible. You can also simply reimplement the `resizeEvent` of the container widget (the window) and do the layout there, although that would be just a more awkward API for the same code you need for the custom QLayout. – Kuba hasn't forgotten Monica Jul 13 '15 at 21:53
-
Using a snapshot and re sizing would work best. I'll look up how to do that. – pmaurais Jul 14 '15 at 12:53
-
But be careful: you're presuming a solution without telling us what the problem is. Please show us what widgets you have, and how do you wish them to be laid out. Also note that your solution will completely fall apart if the application is translated, or the user selects a large font for it for reasons of accessibility, etc. Your initial layout will simply be inadequate, and scaling it may not help at all. You're setting yourself up for a mountain of work that is already mostly done in the layout system. Or you could use QML with its saner approach to layouting. – Kuba hasn't forgotten Monica Jul 14 '15 at 17:27
1 Answers
0
Is there any way to just make of my widgets and certain percent of the screen.
verticalLayout->addWidget(new QTextEdit);
verticalLayout->addWidget(new QTextEdit);
verticalLayout->setStretch(0, 1); // 33%
verticalLayout->setStretch(1, 2); // 66%
Also, setting minimumSize and maximumSize helps alot.

Amartel
- 4,248
- 2
- 15
- 21