Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-102244

In macos 10.15, using CMake's MACOSX_BUNDLE causes qt5.12.11 to get devicePixelRatio of 1?

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • P3: Somewhat important
    • None
    • 5.12.11
    • None
    • - LG 27", 4k
      - MacOS 10.15.5 (In a virtual machine in win10 21H2)
      - Qt 5.12.11
      - CMake 3.22.2
    • macOS

    Description

      CMake add to MACOSX_BUNDLE to use, I can build to get the .app folder, but Qt5.12.11 show devicePixelRatio: 1 (expected should be 2).

      But when I block the MACOSX_BUNDLE macro, I can't build to get the .app folder, but Qt5.12.11 show devicePixelRatio: 2 (as expected).

      This has been confusing me for over a month and I don't know if this is a Qt bug or a CMake bug? Does anyone know the answer?

      In macos systems with high resolution display (Retina Display), the device pixel ratio is usually 2.

       

      ENV:

      • LG 27", 4k
      • MacOS 10.15.5 (In a virtual machine in win10 21H2)
      • Qt 5.12.11
      • CMake 3.22.2

       

      Deam:

      // CMakeLists.txt
      cmake_minimum_required(VERSION 3.5)project(Example VERSION 0.1 LANGUAGES CXX)set(CMAKE_INCLUDE_CURRENT_DIR ON)set(CMAKE_AUTOUIC ON)
      set(CMAKE_AUTOMOC ON)
      set(CMAKE_AUTORCC ON)set(CMAKE_CXX_STANDARD 17)
      set(CMAKE_CXX_STANDARD_REQUIRED ON)find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
      find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)set(PROJECT_SOURCES
              main.cpp
      )if (APPLE)
      #    add_executable(Example MACOSX_BUNDLE ${PROJECT_SOURCES})   # devicePixelRatio: 1 ???
          add_executable(Example ${PROJECT_SOURCES})                # devicePixelRatio: 2   not build .app
      else()
      #    add_executable(Example WIN32 ${PROJECT_SOURCES})
      endif()target_link_libraries(Example PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
      
      // main.cpp
      #include <QApplication>
      #include <QScreen>
      #include <QDebug>int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);    qDebug()<< "devicePixelRatio:" <<QApplication::primaryScreen()->devicePixelRatio();    return a.exec();
      }
      

       

      Attachments

        1. 2022-04-02_195339.png
          2022-04-02_195339.png
          160 kB
        2. code.zip
          0.8 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qtbuildsystem Qt Build System Team
            xmuli xmuli tech
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes