Question

Working with Qt 4.8.4 on OS X -- Desktop Application development. I need to be able to detect, at paint time, if I am on a hiDPI display ("retina") or not. Does anyone know how to achieve this?

Was it helpful?

Solution 2

Eventually I just created a small cocoa function to return this value for me. I use it to determine the time of paintEvent whether I should use hiDPI images. Works like charm on my MacBook Pro 15" Retina.

bool MYAppCocoaServices::isHiDPI(QWidget * widget)
{
    NSView* view = reinterpret_cast<NSView*>(widget->winId());
    CGFloat scaleFactor = 1.0;
    if ([[view window] respondsToSelector: @selector(backingScaleFactor)])
        scaleFactor = [[view window] backingScaleFactor];

    return (scaleFactor > 1.0);
}

I am building this .mm file conditionally on Mac only and call this static function from my c++ code on Mac.

OTHER TIPS

You can use QScreen for this in Qt 5, and in Qt 4 you can use the QSystemDisplayInfo class from Qt Mobility.

For Qt 4

There is QSystemDisplayInfo - http://doc.qt.digia.com/qtmobility/qsystemdisplayinfo.html

The relevant methods are getDPIHeight and getDPIWidth.

You could also use QDesktopWidget's physicalDpiX and physicalDpiY methods.

For Qt 5

Use QScreen - http://qt-project.org/doc/qt-5.0/qtgui/qscreen.html#physicalDotsPerInch-prop

((QGuiApplication*)QCoreApplication::instance())
    ->primaryScreen()->physicalDotsPerInch()

There are also physicalDotsPerInchX and physicalDotsPerInchY.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top