Skip to content

Commit

Permalink
add high DPI support
Browse files Browse the repository at this point in the history
  • Loading branch information
LiangliangNan committed Jan 27, 2021
1 parent b453898 commit df9ebe0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
32 changes: 18 additions & 14 deletions PolyFit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
4 changes: 4 additions & 0 deletions PolyFit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit df9ebe0

Please sign in to comment.