From df9ebe069de2c49c841685566cb430585d0e22e1 Mon Sep 17 00:00:00 2001 From: Liangliang Nan Date: Wed, 27 Jan 2021 16:58:09 +0100 Subject: [PATCH] add high DPI support --- PolyFit/CMakeLists.txt | 32 ++++++++++++++++++-------------- PolyFit/main.cpp | 4 ++++ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/PolyFit/CMakeLists.txt b/PolyFit/CMakeLists.txt index ddb1c838..0e8c8c56 100644 --- a/PolyFit/CMakeLists.txt +++ b/PolyFit/CMakeLists.txt @@ -96,10 +96,23 @@ set(${PROJECT_NAME}_RESOURCES if( APPLE ) # set also the icon -# set_source_files_properties("${CMAKE_CURRENT_LIST_DIR}/Resources/PolyFit.icns" PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") -# set(MACOSX_BUNDLE_ICON_FILE ${CMAKE_CURRENT_LIST_DIR}/Resources/PolyFit.icns ) - - add_executable( ${PROJECT_NAME} MACOSX_BUNDLE ${${PROJECT_NAME}_HEADERS} ${${PROJECT_NAME}_SOURCES} ${${PROJECT_NAME}_FORMS} ${${PROJECT_NAME}_RESOURCES} ) + # This tells CMake where to find and install the ICON file + set(${PROJECT_NAME}_ICON ${CMAKE_CURRENT_SOURCE_DIR}/Resources/PolyFit.icns) + set_source_files_properties(${${PROJECT_NAME}_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") + + add_executable( ${PROJECT_NAME} MACOSX_BUNDLE ${${PROJECT_NAME}_ICON} ${${PROJECT_NAME}_HEADERS} ${${PROJECT_NAME}_SOURCES} ${${PROJECT_NAME}_FORMS} ${${PROJECT_NAME}_RESOURCES} ) + + set_source_files_properties(${${PROJECT_NAME}_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") + + ## Note: On macOS, high-DPI support is enabled by settings in the Info.plist file. Make sure they are present. + ## For more information, see: http://doc.qt.io/qt-5/highdpi.html + ## Enable high DPI support by using my Info.plist file in which I added NSHighResolutionCapable to be true. + set_target_properties(${PROJECT_NAME} PROPERTIES + INSTALL_RPATH "@executable_path/../Frameworks" + MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME} + MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Mac/PolyFit.plist" + MACOSX_BUNDLE_ICON_FILE PolyFit.icns + ) else() add_executable( ${PROJECT_NAME} ${${PROJECT_NAME}_HEADERS} ${${PROJECT_NAME}_SOURCES} ${${PROJECT_NAME}_FORMS} ${${PROJECT_NAME}_RESOURCES} ) endif() @@ -121,13 +134,4 @@ target_link_libraries( ${PROJECT_NAME} Qt5::Widgets ) target_link_libraries( ${PROJECT_NAME} Qt5::OpenGL ) target_link_libraries( ${PROJECT_NAME} Qt5::Xml ) -target_link_libraries( ${PROJECT_NAME} basic math model method renderer 3rd_glew 3rd_QGLViewer-2.6.3) - - - -# Note: On macOS, high-DPI support is enabled by settings in the Info.plist file. Make sure they are present. -# For more information, see: http://doc.qt.io/qt-5/highdpi.html -# Enable high DPI support by using my Info.plist file in which I added NSHighResolutionCapable to be true. -if( APPLE ) - set_target_properties( ${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Mac/PolyFit.plist ) -endif() +target_link_libraries( ${PROJECT_NAME} basic math model method renderer 3rd_glew 3rd_QGLViewer-2.6.3) \ No newline at end of file diff --git a/PolyFit/main.cpp b/PolyFit/main.cpp index 2d0ea692..adaea4e4 100644 --- a/PolyFit/main.cpp +++ b/PolyFit/main.cpp @@ -45,6 +45,10 @@ int main(int argc, char **argv) setlocale(LC_NUMERIC, "C"); #endif +#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) + QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); +#endif + QApplication app(argc, argv); MainWindow window;