Results 1 to 9 of 9

Thread: Widget size in layouts with different screen resolution problem [S60]

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Widget size in layouts with different screen resolution problem [S60]

    I'm not sure that i really understand your problem, but have you tried MinimumExpanding:
    Qt Code:
    1. label1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
    2. //...
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2009
    Location
    Kraków, Poland
    Posts
    6
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Widget size in layouts with different screen resolution problem [S60]

    Nope, the last one does the same effect as picture 3)
    AFAIK Expanding and MinimumExpanding does not differ very much (later one sets a minimum size at minimumSizeHint(?)).

    I'll try once again:
    Labels should have their maximum size if possible. By maximum size i dont mean 'expand to infinity/screen size' but expand to the maximum size i set (3x120 in the example code).
    So if labels vertical size is 360 and display vertical size is 300 all 3 labels will have 100 v-size and will fill whole screen idealy. But if display is bigger then 360 v-size then labels should reach their maximum size (3x120) and be aligned at the top of the screen (like in picture 2) and the empty, unused space should be at the bottom.

    And like i said earlier - do not be suggested by the code i posted. Setting maximum size of widgets this way or assigning policies to them might not be the good solution.

    C'mon, somebody had to the have the same problem someday

  3. #3
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Widget size in layouts with different screen resolution problem [S60]

    You can edit the policies for labels to make them expand "larger" then the spacer (I think i finally understood your problem )
    Qt Code:
    1. //...
    2. label1->setMaximumHeight(120);
    3. label2->setMaximumHeight(120);
    4. label3->setMaximumHeight(120);
    5.  
    6. QSizePolicy policy = label1->sizePolicy();
    7. policy.setVerticalStretch(3); //don't remember the exact "formula" but 3 should be enough
    8. label1->setSizePolicy(policy);
    9.  
    10. label2->setSizePolicy(policy);
    11.  
    12. label3->setSizePolicy(policy);
    13.  
    14.  
    15. QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
    16.  
    17. mainLayout->addWidget(label1);
    18. mainLayout->addWidget(label2);
    19. mainLayout->addWidget(label3);
    20. mainLayout->addSpacerItem(spacer);
    21.  
    22. //don't set sizepolicy again... if you want other then prefered set it before policy edit
    23. //label1->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
    24. //label2->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
    25. //label3->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
    26. //...
    To copy to clipboard, switch view to plain text mode 
    Last edited by Zlatomir; 20th June 2010 at 13:19.

  4. The following user says thank you to Zlatomir for this useful post:

    JacquesBaniaque (20th June 2010)

  5. #4
    Join Date
    Sep 2009
    Location
    Kraków, Poland
    Posts
    6
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Widget size in layouts with different screen resolution problem [S60]

    Yes! That's it! Problem solved!
    Thanks Zlatomir

    Still i would really appreciate if You explained why this one worked and previous did not or at least direct me to some source were i could read about it

  6. #5
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Widget size in layouts with different screen resolution problem [S60]

    This is the line that does the "magic"
    Qt Code:
    1. policy.setVerticalStretch(3);
    To copy to clipboard, switch view to plain text mode 
    That widgets that will widget->setSizePolicy(policy); will have a 3 times bigger stretch factor (which control the relative size of the widgets in a container dialog/window/widget/etc)

    And in our case all the widgets will occupy more vertical space in container (but no more that 120, because you set up that way), and this will prevent the spacer to expand more (kind of like the widgets/labels have "priority" to expand and the spacer expands in the remaining space if the labels reach the maximum size)
    Last edited by Zlatomir; 20th June 2010 at 20:50.

Similar Threads

  1. How can i make widget automatically adjust screen size
    By kapoorsudhish in forum Qt Programming
    Replies: 3
    Last Post: 23rd October 2009, 15:21
  2. changing screen resolution of touchscreen
    By aj2903 in forum Qt for Embedded and Mobile
    Replies: 7
    Last Post: 8th April 2009, 18:57
  3. Replies: 1
    Last Post: 27th March 2008, 15:10
  4. Screen resolution
    By sabeesh in forum Qt Programming
    Replies: 4
    Last Post: 7th September 2007, 17:00
  5. Screen Resolution
    By vijay anandh in forum Qt Programming
    Replies: 3
    Last Post: 6th October 2006, 13:47

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.