PDA

View Full Version : Expand all widgets depending on screen geometry



Henry Blue Heeler
7th August 2014, 23:56
Instead of using QLayouts, is there a way to expand all widgets based upon the monitor's size (e.g. 1024x768 or 1920x1080)?
I'm talking application wise, like qApp->something_freaking_magic().
Horizontal and vertical global expansion and/or shrinkage, including fonts.

d_stranz
8th August 2014, 17:46
QLayout doesn't care how big its widget is (the one it is managing the layout of child widgets for). It will expand itself and the space between child widgets as appropriate to fill the widget unless horizontal or vertical spacers are used to constrain the child widget sizes. You can demonstrate this to yourself by making a simple dialog with a grid layout and a few buttons. In your initial construction of the dialog, you can query QScreen for the geometry and scale the dialog accordingly. You might have to change the size policy of the child widgets to ensure they expand in both width and height. Some widgets with "preferred" sizes won't expand in one direction or the other.

The fonts don't grow with the widgets, so if you want everything magnified you'll have to also scale the QGuiApplication::font(). Doing this first should cause widgets with preferred size to expand when constructed to accommodate the font.

Doing this without layouts basically means you have to duplicate everything that QLayout gives you for free, so why not just use them?

Of course, if you do all of this you will thoroughly annoy all of your users because your application will behave differently from every other app on their system. Be prepared to remove this "feature" once the complaints start coming in.

Henry Blue Heeler
8th August 2014, 19:43
Of course, if you do all of this you will thoroughly annoy all of your users because your application will behave differently from every other app on their system. Be prepared to remove this "feature" once the complaints start coming in.

You're preaching to the choir on that point. Wasn't my idea and I'm pushing against it. I'll show your post to the powers that be and hopefully convince them otherwise.

One problem I find annoying with layouts is trying to add layouts to existing windows using Design. It resizes the widgets crazily, so I need to educate myself more about sizePolicy.

Thanks again for the reply.

d_stranz
8th August 2014, 20:03
Wasn't my idea and I'm pushing against it.

Ah, the joys of working in an environment where there's a marketing department which understands the customers' needs.


One problem I find annoying with layouts is trying to add layouts to existing windows using Design. It resizes the widgets crazily, so I need to educate myself more about sizePolicy.

If I need to rework an existing layout in Designer, my solution is generally to break the top-level layout, resize the widget to make it temporarily much larger, put the new layout in place, then drag and drop the existing children into it. Finally I delete the old layout and resize the widget again. I'll sometimes go into the .ui file and manually edit it to make sure the new layout is the top level one.

You can prevent child widgets from resizing in a layout either by giving them fixed sizes or by using spacers which will usually limit them to a preferred size.