Results 1 to 2 of 2

Thread: resizing based om the system screen resolutions

  1. #1
    Join Date
    Sep 2024
    Posts
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question resizing based om the system screen resolutions

    HI ALL,
    Iam newbie to this Qt5 ,HERE i want to resize my gui based on system resolutions. and my application screen is like 768x1024 size for 1920 x 1080 system resolution. iam using the resize as

    Qt Code:
    1. QScreen *screen = QGuiApplication::primaryScreen();
    2. if (screen) {
    3. QRect screenGeometry = screen->geometry();
    4. int screenWidth = screenGeometry.width();
    5. int screenHeight = screenGeometry.height();
    6. this->resize(screenWidth, screenHeight);
    7. }
    To copy to clipboard, switch view to plain text mode 
    Screen Size: 800 x 600
    Window Size: 800 x 600

    Screen Size: 1920 x 1080
    Window Size: 1920 x 1080

    Screen Size: 1680 x 1050
    Window Size: 1680 x 1050

    if i use
    Qt Code:
    1. const int defaultWidth = 768;
    2. const int defaultHeight = 1024;
    3. this->resize(defaultWidth,defaultHeight);
    To copy to clipboard, switch view to plain text mode 

    Screen Size: 1920 x 1080
    Window Size: 768 x 1024

    Screen Size: 800 x 600
    Window Size: 800 x 600 its fit to the screen but i need it in 450x600 resolutions according to the 768x1024 gui screen size .
    Last edited by d_stranz; 19th September 2024 at 19:08. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,299
    Thanks
    312
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: resizing based om the system screen resolutions

    Are you using layouts for the widgets in your GUI? That will ensure that when the GUI is resized, the contents will be moved to best fit locations when possible. If the minimum sizes for the widgets in your GUI are too large for the window size, then the result might have overlapping widgets. If you aren't using layouts, then some widgets might be outside the window bounds and invisible.

    To solve your problem, I suggest you just make a set of conditional statements to resize your GUI based on the screen size:

    Qt Code:
    1. QScreen *screen = QGuiApplication::primaryScreen();
    2. if (screen) {
    3. QRect screenGeometry = screen->geometry();
    4. int screenWidth = screenGeometry.width();
    5. int screenHeight = screenGeometry.height();
    6.  
    7. if ( screenWidth >= 1920 && screenHeight >= 1080 ) // biggest GUI possible
    8. resize( 768, 1024 );
    9. else if ( screenWidth >= 800 && screenHeight >= 600 ) // either height or width above were too small
    10. resize( 800, 600 );
    11. else // screen is smaller than anything above. Hope for the best.
    12. resize( 450, 600 );
    13. }
    To copy to clipboard, switch view to plain text mode 

    You can add as many if/else clauses as you need to accommodate all of the screen sizes you think you'll need. Just make sure you order the clauses from largest to smallest so you end up with the largest size window for the screen and choose sizes so your layout still looks good.

    You can easily test this by temporarily setting screenWidth and screenHeight instead of using the result returned from the QScreen.
    Last edited by d_stranz; 19th September 2024 at 19:38. Reason: spelling corrections
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 2
    Last Post: 23rd July 2019, 20:14
  2. Replies: 4
    Last Post: 27th August 2013, 15:49
  3. Resizing screen dimensions using backbuffer in QT?
    By JimDaniel in forum Qt Programming
    Replies: 1
    Last Post: 25th September 2007, 00:13
  4. QTimer based Splash Screen
    By bpetty in forum Newbie
    Replies: 6
    Last Post: 15th December 2006, 01:51
  5. Dialog sizes and different screen resolutions.
    By hvengel in forum Qt Tools
    Replies: 3
    Last Post: 2nd April 2006, 11:05

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.