How do you correctly handle scaling across various display sizes?
-
Hello,
I'm working on a basic calculator application and have configured it to be a fixed window size. Using this setup on my main machine works fine and as expected, although when I build my project on new macbook the window widgets are squished. In addition to being squished, it appears that the code I use to obtain the coordinates of certain widgets and drawtext based on those values is also incorrect. Right now I thought I would get away with using fixed numbers but it appears that the difference in screen resolution may be impacting the drawing?
To make things easier instead of me guessing where issues are and attempting to share snippets, here is a link to the full source: https://github.com/droogie/bincalc
Feel free to ask for clarification on anything specific, this is my first Qt project so I might be doing things in an incorrect or confusing manner.
This is it looking correctly on linux:
This is how it displays on a macbook:
At first glance the most obvious difference was the column size for the main gridlayout. I messed with adjusting columnspacing values to give the first column a larger width, thinking that it might solve the issue although I was not getting expected results. I am also fearing that my approach of drawing text (making the vertical labels for the bit checkboxes) is probably not the correct way to handle the situation and would love some recommendations regarding that if anyone has any.
-
Hi and welcome to decent,
From a quick check, you are using hard coded values that play fine at standard resolution but not on retina displays.
Did you already check the high dpi chapter in Qt's documentation ?
-
Thanks for the reply. Looking at the documentation and messing with some of the attributes, it seems that since I'm using qt6 all of the high dpi settings are automatically enabled. I've toyed with different settings with no differences and also warnings of attributes being deprecated and them no longer taking effect.
I'm curious if there's a separate difference between the environments that's causing the columns to be sized differently? The main widget is in a grid layout and we can see the left column is being squished in the MacOS build due to the right column being unnecessarily wide. Any thoughts?
-
What I think happens is that you do not take into account the devicePixelRatio into your paint maths. So it works fine as long as you are working on a screen which has a 1:1 ratio but as soon as you get on a retina display for example, you are working with a 2:1 ratio.