Results 1 to 4 of 4

Thread: Expand all widgets depending on screen geometry

  1. #1
    Join Date
    Dec 2013
    Location
    Colorado
    Posts
    45
    Thanks
    15
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Expand all widgets depending on screen geometry

    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.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Expand all widgets depending on screen geometry

    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.
    Last edited by d_stranz; 8th August 2014 at 16:53.

  3. The following user says thank you to d_stranz for this useful post:

    Henry Blue Heeler (8th August 2014)

  4. #3
    Join Date
    Dec 2013
    Location
    Colorado
    Posts
    45
    Thanks
    15
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Expand all widgets depending on screen geometry

    Quote Originally Posted by d_stranz View Post
    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.

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Expand all widgets depending on screen geometry

    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.

  6. The following user says thank you to d_stranz for this useful post:

    Henry Blue Heeler (8th August 2014)

Similar Threads

  1. Ho do I Expand QGrpahicsView off screen inside a QScrollArea?
    By hybrid_snyper in forum Qt Programming
    Replies: 1
    Last Post: 5th June 2013, 21:21
  2. PyQt Hide off screen widgets
    By Alterah in forum Newbie
    Replies: 0
    Last Post: 21st January 2012, 05:19
  3. resizing widgets depending on a main widget size
    By luf in forum Qt Programming
    Replies: 6
    Last Post: 10th October 2009, 16:13
  4. Replies: 1
    Last Post: 20th July 2008, 19:47
  5. picking geometry in qt custom widgets
    By notsonerdysunny in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2007, 23:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.