QML Application and HiDPI



  • Hi,

    I am developing a new qml desktop application, and want to make sure it runs on HiDPI screens as well as on normal screens. I found https://doc.qt.io/qt-5.10/highdpi.html but still I dont know what practices I should follow when designing my app. The documentation says

    Replace hard-coded sizes in layouts and drawing code by values calculated from font metrics or screen size.

    Are there other things to consider? Also, how would this be done in practice (e.g. get the font metric or the screen size). Once I have them, and e.g. I define a rectangle, should I then define it like ceil(0.3*screenSize)? I guess I should try to always have integer pixels right?

    Would it be a good idea to define a global scaling value, and multiply every width by this value?



  • @maxwell31 Generally on HighDPI ("retina") screens even if the screen is UHD 3840x2160 resolution your QML will use "logical" pixels and your code will get the impression the screen is 1920x1080. No scaling factor needed... just code as if you were coding for 1920x1080 and it should all look beautiful on a HighDPI UHD. No explicit global scaling factor required.

    All my apps are designed to run full-screen or in a big window... I mainly work top down coding everything in terms of proportions of it's parent's size (which at the top level is the screen size). Doesn't fail gracefully for small windows or extreme aspect ratios but its good enough for me (these days the main challenge is getting it to look good on all of portrait and landscape and 4:3-HD aspect ratio screens on mobile. So long as those are good, the desktop users can take their chances resizing to other goofy shapes).

    Personally I've hardly ever bothered rounding size calculations to integer pixels unless I really needed to (e.g rectangles with hard 1 pixel borders can look different depending on sub-pixel positioning and it's worth rounding... but bigger solid blocks of colour or text just work fine wherever you put them). Exactly how good it looks might depend on antialiasing settings but I've not experimented enough to comment further, or particularly felt the need to.



  • Thanks for the helpfull post. You are right, once I set

        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    

    It is working nicely. There is one thing though, I do some drawing in updatePaintNode using openGL, there the line width is not automatically scaled, but this should also not be a big problem.



  • My suggestions would include:

    •using quick controls 2 as your starting point, since it was designed for higher resolutions

    •Use anchors rather than absolute pixel positions.

    •Use scalable graphics (PDFs, SVGs) rather than fixed resolution graphics, so images don't' look pixelated at higher resolution.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.