HiDPI mode detection

Working with Qt 4.8.4 on OS X - Desktop Application Development . I should be able to detect, while drawing, if I am on the hiDPI screen ("retina") or not. Does anyone know how to achieve this?

+6
source share
2 answers

In the end, I just created a little cocoa function to return this value to me. I use it to determine the paintEvent time whether to use hiDPI images. Works like a 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 create this .mm file conditionally only on Mac and call this static function from my C ++ code on Mac.

+4
source

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 appropriate methods are getDPIHeight and getDPIWidth .

You can also use the QDesktopWidget 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 .

+3
source

Source: https://habr.com/ru/post/944900/


All Articles