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?
2 Answers
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
.

- 18,515
- 13
- 84
- 125
-
QSystemDisplayInfo does not exist on any file on my disk. I am building a dekstop application, using the "regular" Qt 4.8.4. – JasonGenX May 13 '13 at 18:07
-
@RM1970 It is part of Qt Mobility, which might not be in the package you downloaded. Try `QDesktopWidget` instead. – Venemo May 13 '13 at 18:09
-
1The method analogous to the accepted answer is `QScreen:: devicePixelRatio()` – yig Mar 04 '18 at 19:11
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.

- 4,952
- 27
- 106
- 198
-
Why the vote down? Qt 4.8 doesn't support Retina fully and I don't want to use modules I don't need just to ask this boolean question. It works nicely, so why vote it down? – JasonGenX May 20 '13 at 03:46