QtCS2015 ResolutionIndependence

From Qt Wiki
Revision as of 13:26, 23 August 2015 by AutoSpider (talk | contribs) (Simplify punctuation)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Resolution independence in Qt

There are two possible approaches for making your Qt application work on modern high-density displays:

  1. Write your program properly, using any new API we discuss today; OR
  2. Let Qt scale your 20th-century-style application, and deal with the inconsistencies

The scaling approach

In 5.4 and 5.5, scaling was implemented in the platform plugins, leading to duplication of code. Scaling will be cross-platform in 5.6

What works?

  • Scaling is always opt-in
    • QT_SCALE_FACTOR
    • QT_AUTO_SCREEN_SCALE_FACTOR
  • integer scale factors officially supported
    • beware the Qt rectangle definition (add 0.5 to all coordinates)
    • non-integer factors "work", but expect painting artifacts
  • Different scale factors for multiple screens
  • breaking some invariants with global mouse position

Issues/TODOs

  • Calculation of logical DPI
    • Do we divide by scaleFactor or not?
      • world view 1: scale is a zoom
      • world view 2: point size is a physical size
  • font hinting
    • dynamically turn on and off based on scale factor
    • do hinting in scaled coordinates
  • screen position mapping
  • QT_FONT_DPI currently only on xcb
  • Screen change event when scaleFactor changes
  • Touch events are untested

Discussion

We will not change the hinting code to work in scaled coordinates. That is too much work for something that is essentially a workaround. The important thing is to keep hinting on when the scale factor is one, even if QT_AUTO_SCREEN_SCALE_FACTOR is set. This means we have to be able to tear down the font engine when a high-DPI screen is plugged in later.

Some applications need to handle all scaling themselves, such as KDE's Plasma, which needs to work in actual device coordinates. Therefore there should be a way to "opt out of the opt-in" by setting an application attribute. We do not want to make QHighDpiScaling public, but we may want to expose getters for QScreen and QWindow scale factors.

KDE would like to have something more convenient than environment variables. (Some kind of window manager property.) This would mean that the platform plugin should be able to set scaling/auto scaling.

Future direction: making it easier to write resolution-aware applications

  • Resolution independent units in Qt Quick
  • Scaling the top-level item

Discussion

  • 3 different concepts:
    • physical units
    • project specific grid units
    • standard grid units

This is just convenience/optimization: you can do everything yourself with the current version of Qt by multiplying in your own conversion factor. Will not be in 5.6