Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

devicePixelRatioF not set under macOS



  • Hello,

    I'm working on a cross platform application for Linux, Window and macOS and there is part where I need to scale something based on the screen scaling. So far I have been using desktopWidget->devicePixelRatioF() under Linux and Windows to get the scale factor and that works fine but now one of my users run into an issue with macOS where there is obviously screen scaling going on but the devicePixelRatio is always set to 1.
    This is how scaling variables look like on his machine:

    devicePixelRatio: 1
    devicePixelRatioF: 1
    logicalDpiX: 72
    logicalDpiY: 72 
    physicalDpiX: 114
    physicalDpiy: 114
    

    Tested in macOS VM (where is cannot enable screen scaling):

    devicePixelRatio: 1
    devicePixelRatioF: 1
    logicalDpiX: 72
    logicalDpiY: 72 
    physicalDpiX: 72
    physicalDpiy: 72
    

    Has anyone run into such an issue?

    I have tested this with Qt 5.13.2 and 5.15.0, behaves the same.


  • Lifetime Qt Champion

    Since QDesktopWidget is deprecated I wouldn't be surprised when it is broken on mac.



  • Well, the one coming from the QScreen doesn't seem to be correct either. I've got the QScreen from QApplication::primaryScreen()
    and see following:

    QScreen devicePixelRatio: 1
    QScreen logicalDotsPerInch: 72
    QScreen logicalDotsPerInchX: 72
    QScreen logicalDotsPerInchY: 72
    QScreen physicalDotsPerInch: 113.5
    QScreen physicalDotsPerInchX: 113.5
    QScreen physicalDotsPerInchY: 113.5
    

    According to my user the DPI he should have 227 DPI:
    "13-inch MacBook Pro models introduced in late 2012 or later. Native resolution: 2560 x 1600 at 227 pixels per inch. Support for millions of colors."