I want to follow the long-term path as stated in document so automatic scaling like QT_AUTO_SCREEN_SCALE_FACTOR
is not acceptable.
Without a layout, I can use a value from devicePixelRatioF
to scale the widgets. When using layout the size and position of the widgets will be handled by the layout. So how do scale widgets according to screen DPI in this case?
For controlling scale you need to use layouts.see Layout Management document.
and Qt::AA_EnableHighDpiScaling
Enables high-DPI scaling in Qt on supported platforms (see also High DPI Displays). Supported platforms are X11, Windows and Android. Enabling makes Qt scale the main (device independent) coordinate system according to display scale factors provided by the operating system. This corresponds to setting the QT_AUTO_SCREEN_SCALE_FACTOR environment variable to 1. This attribute must be set before
so add this line in your main.cpp
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
Updated:
When a widget enters the layout you can't change its width or height from the geometry section BUT you can change its size policy or scale widgets with Max/Min section. This doesn't relate to DPI.
from Doc that you mentioned it says that:
In the long term, the application should be adapted to run unmodified:
- Always use the qreal versions of the QPainter drawing API.
- Size windows and dialogs in relation to the corresponding screen size.
- Replace hard-coded sizes in layouts and drawing code with values calculated from font metrics or screen size.
means that you should follow that 3 suggestions
means that you can calculate the size by yourself. (hard-coded) In my experience, I never have an issue with scale when I use layout on different devices or monitors.
I need to know what you see on your screen and what expect to be.