Retina support in Qt5 on OS X
Asked Answered
H

2

10

I'm writing a C++ graphical application using Qt 5.5.0 on OS X El Capitan on a Retina MacBook Pro. Text is pixelated throughout the application so I suspect that high DPI mode is not used. My Info.plist contains the following definition:

<key>NSHighResolutionCapable</key>
    <true/>

How do I enable high resolution mode (especially for text rendering) in a Qt application on OS X?

Hyperaesthesia answered 25/12, 2015 at 18:54 Comment(2)
My Qt Widgets application is perfectly fine on retina, and I don't have that key in my .plist. I have no special keys, in fact. Just checked.Hoekstra
Just wanted to add that all text in the app is pixelated, even system dialogs.Hyperaesthesia
H
6

Make sure your info.plist has the NSPrincipalClass and NSApplication keys. According to the Qt docs, NSHighResolutionCapable is optional and true by default. Here's my entire plist for reference:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
    <key>NSPrincipalClass</key>
    <string>NSApplication</string>
    <key>CFBundleIconFile</key>
    <string>@ICON@</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleGetInfoString</key>
    <string>Created by Qt/QMake</string>
    <key>CFBundleSignature</key>
    <string>@TYPEINFO@</string>
    <key>CFBundleExecutable</key>
    <string>@EXECUTABLE@</string>
    <key>CFBundleIdentifier</key>
    <string>com.my.@EXECUTABLE@</string>
</dict>
</plist>

If you insist on specifying NSHighResolutionCapable manually, note that you did it wrong in your question. Here's the right syntax from the same docs:

<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSHighResolutionCapable</key>
<string>True</string>
Hoekstra answered 25/12, 2015 at 19:24 Comment(4)
I tried your plist and manually correctly specifying NSHighResolutionCapable but it's still blurry/pixelated.Hyperaesthesia
After testing some more, your answer is actually correct. My running directory contained an old copy of the .plist. Manually setting NSHighResolutionCapable was not necessary.Hyperaesthesia
@SurvivalMachine: unless you need it, I'm fairly sure you can throw the plist away entirely. Should work without it as well.Hoekstra
Big thank you... super obvious (sarcasm, many thanks to Apple) add NSPrincipalClass equal to NSApplication and it indeed started to work.Bushhammer
A
3

You also need to call QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps) just after creating QApplication object to be able to use High DPI pixmaps. Read more here: http://doc.qt.io/qt-5/qpixmap.html#devicePixelRatio

Allanite answered 26/12, 2015 at 2:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.