7

I have created a simple Qt application with only a MainWindow and a Button. When I build it in Qt using Qmake it works fine and UI is good as well. On other hand if build it using CMake it works fine but application UI is blurry.

Could anybody please let me know how to fix it. Thank you.

UI of Application Generated with QMake- enter image description here UI of Application Generated with CMake enter image description here

My CmakeList.txt File

make_minimum_required(VERSION 3.0.2)
project(MyProject)

find_package(Qt5Widgets 5.9 PATHS /usr/local/Cellar/qt/5.9.1)
find_package(OpenGL)
#find_package(IOKit PATHS /System/Library/Frameworks/IOKit.framework/Versions/A)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

add_library(mainwindow mainwindow.cpp)
target_link_libraries (mainwindow Qt5::Widgets)

#set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE YES)
add_executable(MyProject MACOSX_BUNDLE main.cpp)
target_link_libraries (MyProject mainwindow ${OPENGL_gl_LIBRARY})

Project Structure-

enter image description here

My Machine Configuration-

enter image description here

Anwar Shaikh
  • 1,591
  • 3
  • 22
  • 43
  • Is it only "blurry" on a Retina display? Is the blurriness simply that it's not running in @2x mode? – Ssswift Jul 24 '17 at 17:09
  • @Ssswift Unfortunately, I am not sure of that as I have not tested with non-retina Mac. In that case what would be the fix, I can try if that can fix the issue. – Anwar Shaikh Jul 24 '17 at 17:22
  • CMake is just a (meta) build system. It, in itself, cannot be responsible for making your app blurred. – Jesper Juhl Jul 24 '17 at 17:57
  • @JesperJuhl Agreed! The point here is- I believe there must be some Qt GUI specific configuration needs to be done in `CMakeLists.txt` to make it work properly. – Anwar Shaikh Jul 24 '17 at 18:41

1 Answers1

7

Solved!

I think creating bundle for MacOS needs following keys to be set in Info.plist file as it mentioned here.

Creating a custom Info.plist file with adding following keys solved the issue-

<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSHighResolutionCapable</key>
<string>True</string>

To add custom Info.plist add following line in CMakeLists.txt file-

# Set a custom plist file for the app bundle
set_target_properties(MyProject PROPERTIES MACOSX_BUNDLE_INFO_PLIST <dir>/Info.plist)
Anwar Shaikh
  • 1,591
  • 3
  • 22
  • 43