Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building a simple Qt UI Application using CMake creates blurry UI

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

like image 374
Anwar Shaikh Avatar asked Jul 24 '17 16:07

Anwar Shaikh


People also ask

Does Qt use CMake?

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.

What is CMake Qt GUI?

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.

What is CMake in Qt Creator?

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.

What is CMake and Qmake?

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).


1 Answers

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)
like image 129
Anwar Shaikh Avatar answered Sep 27 '22 20:09

Anwar Shaikh