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
-
UI of Application Generated with
CMake
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-
My Machine Configuration-
Qt relies on some bundled tools for code generation, such as moc for meta-object code generation, uic for widget layout and population, and rcc for virtual file system content generation. These tools may be automatically invoked by cmake(1) if the appropriate conditions are met.
Qt based user interface for CMake (cmake-gui) CMake is used to control the software compilation process using simple platform and compiler independent configuration files. CMake generates native makefiles and workspaces that can be used in the compiler environment of your choice.
CMake generates native build configurations and workspaces that you can use in the compiler environment of your choice. You can use CMake from Qt Creator to build applications for the desktop, as well as mobile and embedded devices. You can also build single files to test your changes.
CMake is an alternative to qmake for automating the generation of build configurations. Setting Up Qbs. Qbs is an all-in-one build tool that generates a build graph from a high-level project description (like qmake or CMake do) and executes the commands in the low-level build graph (like make does).
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With