Dynamic scaling UI components in Qt Creator
-
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!!!!
@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.
-
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!!!!
@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. -
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?@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. -
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.