Dynamic scaling UI components in Qt Creator
-
wrote on 7 Aug 2024, 02:52 last edited by
Hi so i'm working on a project with qt, i design my app and all of its ui component in 100% scale screen, but when i change my screen resolution to 150%, it shrunk and can't scale back, and when i change back to 100% this happens. So i want to ask if there's any way that i can dynamically scaling my app or is there any other way that i can make my app responsive. I can't use box layouts or any layouts because my app has a lot of different labels, buttons and many other ui components that are placed in many places in my app. Thanks!!!!
-
Hi so i'm working on a project with qt, i design my app and all of its ui component in 100% scale screen, but when i change my screen resolution to 150%, it shrunk and can't scale back, and when i change back to 100% this happens. So i want to ask if there's any way that i can dynamically scaling my app or is there any other way that i can make my app responsive. I can't use box layouts or any layouts because my app has a lot of different labels, buttons and many other ui components that are placed in many places in my app. Thanks!!!!
wrote on 7 Aug 2024, 03:46 last edited by@tdc0311 said in Dynamic scaling UI components in Qt Creator:
I can't use box layouts or any layouts because my app has a lot of different labels, buttons and many other ui components that are placed in many places in my app.
Then you have to do all the work yourself. I am going to assume you are using Windows.
You might be able to detect the scaling change in a handler attached to QCoreApplication::installNativeEventFilter(). You'd be looking for WM_DPICHANGED I guess. Not sure if there is a Qt-translated version present in the Qt event system.
BTW: Nothing in your screenshots look like it could not be done with layouts. Only you know what the rest of it looks like though.
-
wrote on 7 Aug 2024, 06:13 last edited by
I'd rather disable high dpi scaling in Qt if layout is not available.
-
Hi so i'm working on a project with qt, i design my app and all of its ui component in 100% scale screen, but when i change my screen resolution to 150%, it shrunk and can't scale back, and when i change back to 100% this happens. So i want to ask if there's any way that i can dynamically scaling my app or is there any other way that i can make my app responsive. I can't use box layouts or any layouts because my app has a lot of different labels, buttons and many other ui components that are placed in many places in my app. Thanks!!!!
wrote on 7 Aug 2024, 12:45 last edited by Pl45m4 8 Jul 2024, 13:20@tdc0311 said in Dynamic scaling UI components in Qt Creator:
I can't use box layouts or any layouts because my app has a lot of different labels, buttons and many other ui components that are placed in many places in my app.
Why you think so? From looking at your design I don't know what prevents you from using layouts.
At least some layout(s) like cascading vertical/horizonal layouts should work. -
wrote on 8 Aug 2024, 12:37 last edited by John Van 8 Aug 2024, 12:39
Try using this code.
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
Also, is the main page using QTabWidget? It looks very nice. Would you mind sharing this part of the code? -
Try using this code.
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
Also, is the main page using QTabWidget? It looks very nice. Would you mind sharing this part of the code?wrote on 8 Aug 2024, 16:28 last edited by@John-Van said in Dynamic scaling UI components in Qt Creator:
Also, is the main page using QTabWidget? It looks very nice. Would you mind sharing this part of the code?
Either this or a heavily styled
QStackedWidget
with buttons on the left to activate and show the matching page widget. -
wrote on 9 Aug 2024, 06:53 last edited by
I am not sure if you need to support someone changing the system settings while your app is open. It is such an edge case that I would say it is okay for the user to close and reopen the app. However, this problem might occur when having two monitors with different scaling each. For this we react to showEvent, resizeEvent, and moveEvent to detect when the pixel ratio of the screen changes.
1/7