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
Code:
QScreen *screen
= QGuiApplication
::primaryScreen();
if (screen) {
QRect screenGeometry
= screen
->geometry
();
int screenWidth = screenGeometry.width();
int screenHeight = screenGeometry.height();
this->resize(screenWidth, screenHeight);
}
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
Code:
const int defaultWidth = 768;
const int defaultHeight = 1024;
this->resize(defaultWidth,defaultHeight);
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 .
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:
Code:
QScreen *screen
= QGuiApplication
::primaryScreen();
if (screen) {
QRect screenGeometry
= screen
->geometry
();
int screenWidth = screenGeometry.width();
int screenHeight = screenGeometry.height();
if ( screenWidth >= 1920 && screenHeight >= 1080 ) // biggest GUI possible
resize( 768, 1024 );
else if ( screenWidth >= 800 && screenHeight >= 600 ) // either height or width above were too small
resize( 800, 600 );
else // screen is smaller than anything above. Hope for the best.
resize( 450, 600 );
}
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.