How to do with resolution adaptation?
-
For better layout, I often use plain number to layout, such as
layout->setSpacing(20)
,font.setPixelSize(12);
,etc...(I knowsetPointSize()
can replacesetPixelSize()
to get better adaptation, here is just a example, ignore it.)So, if you use plain numbers to layout your app interface, it will lost it's adaptation.
I think it deeply for some time, finally find a way: by using resolution proportion.
for example,
QSize currentResolution = getResolution(); double resolutionProportion = currentResolution.width() / 1920.0; // 1920 is the resolution's width of your pc on which develop this app ... ... ... layout->setSpacing(20 * resolutionProportion );
Is this a good solution? If not, could you tell me the better or best solution?
Thanks a lot.
-
Hi
You are using an int for resolutionProportion so i fear it will be truncated and zero
for most cases.
To have effect, i think you need something likedouble resolutionProportion = (double )currentResolution.width() / 1920.0;
layout->setSpacing( ceil(20 * resolutionProportion ));
(or floor or round )Other than that, i think the idea is fine enough.
-
Hi
You are using an int for resolutionProportion so i fear it will be truncated and zero
for most cases.
To have effect, i think you need something likedouble resolutionProportion = (double )currentResolution.width() / 1920.0;
layout->setSpacing( ceil(20 * resolutionProportion ));
(or floor or round )Other than that, i think the idea is fine enough.