Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-141448

Actual device pixel ratio inaccessible from QML under Wayland

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Not Evaluated Not Evaluated
    • None
    • 6.10
    • None
    • All, Linux/Wayland

      Under QML, the device pixel ratio is accessible via the attache property Screen.devicePixelRatio.

      But under Wayland (and i think webassembly) Screen devicepixelratio is always rounded to integer, even if fractional scaling is involved, and only QWindow::devicePixelRatio actually gives the real fractional value, but this is not available to QML.

      from the QScreen documentation:

      Note: On some platforms the devicePixelRatio of a window and the screen it is on can be different. Use this function only when you don't know which window you are targeting. If you do know the target window, use QWindow::devicePixelRatio() instead.

       

      If the QML user code needs to draw things as a given device pixels size, or have something be drawn to a consistent size of device pixels across the whole application it needs to access this ratio somehow.

       

      In the attached QMLfile , intended to show issues at a scaling of 125%, can be seen:

      • A red rectangle with height as Screen.devicePixelRatio. On some platforms like Wayland, the rectangle will be 2 pixels tall at 125%
      • 2 blue rectangles: both have height=1but have a different y (their scaled y having a different decimal part): this makes Rectangle vertices snapping differently and even if both have height 1, one will be one pixel tall, the other one 2 pixels tall. This is a problem in UI elements like separator lines which are supposed to have a consistent thickness everywhere
      • 2 green rectangles: those are also 1 logical pixel tall but have antialiasing on: for the same reason they will both appear blurry, and in an inconsistent way between the two making appear they have a different color
      • 2 black rectangles: those have an height of round(1 * 1.25) / 1.25 which makes them snap in a consistent manner and both are exactly 1 device pixel tall

      The current snapping behavior of Rectangle is completely fine for 99% of the cases. perfect device pixel control is needed only in corner cases like separators, which i think makes a strong case for having the Window's effectiveDevicePixelRatio directly available to QML

       

        For Gerrit Dashboard: QTBUG-141448
        # Subject Branch Project Status CR V

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            notmart Marco Martin
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:

                There is 1 open Gerrit change