Qt High DPI Displays

一 相关属性
1 Qt::AA_EnableHighDpiScaling
  • Enables high-DPI scaling in Qt on supported platforms (see also High DPI Displays). Supported platforms are X11, Windows and Android. Enabling makes Qt scale the main (device independent) coordinate system according to display scale factors provided by the operating system. This corresponds to setting the QT_AUTO_SCREEN​_SCALE_FACTOR environment variable to 1. This value has been added in Qt 5.6. This attribute must be set before Q(Gui)Application is constructed.
  • 在支持的平台上启动Qt high-DPI缩放(另请参见High DPI Displays)。支持的平台有X11, Windows 和 Android。该启用使Qt根据操作系统提供的显示缩放因子缩放主(与设备无关)坐标系。这对应于将环境变量QT_AUTO_SCREEN​_SCALE_FACTOR设置为1。该值已在Qt5.6中添加。该属性一定要在Q(Gui)Application被构造前设置。
2 Qt::AA_DisableHighDpiScaling
  • Disables high-DPI scaling in Qt, exposing window system coordinates. Note that the window system may do its own scaling, so this does not guarantee that QPaintDevice::devicePixelRatio() will be equal to 1. In addition, scale factors set by QT_SCALE_FACTOR will not be affected. This corresponds to setting the QT_AUTO_SCREEN​_SCALE_FACTOR environment variable to 0. This value has been added in Qt 5.6. This attribute must be set before Q(Gui)Application is constructed.
  • 禁用Qt中的high-DPI缩放,显示窗口系统坐标。请注意窗口系统可能自行缩放,因此这并不能保证QPaintDevice::devicePixelRatio()将等于0。此外,QT_SCALE_FACTOR设置的缩放因子不会受影响。这对应于将环境变量QT_AUTO_SCREEN​_SCALE_FACTOR设置为0。该值已在Qt5.6中添加。该属性一定要在Q(Gui)Application被构造前设置。
二 High DPI Displays (高DPI显示)
  • High DPI Displays are displays with increased pixel density compared to standard DPI displays.
  • 与校准DPI显示器相比,高DPI显示器具有更高的像素密度。
  • This pixel density is measured in Dots per Inch (DPI) or Pixels Per Inch (PPI), and is determined by the number of display pixels and physical size. This means that the number of pixels alone is not enough to determine if a display falls into the high-DPI category.
  • 该像素密度以每英寸点数(DPI)或每英寸像素数(PPI)度量,并由显示像素的数量和物理大小决定。这意味着仅像素数量不足以确定显示器是否属于high-DPI类别。
  • A 4K monitor has a fixed number of pixels (~8M), however the DPI varies between 185 (23 inch) and 110 (40 inch). The former is around 2x standard 96 DPI desktop resolution, while the latter is barely over it.
  • 4K显示器有固定的像素数(~8M),但是DPI在185(23英寸)和110(40英寸)之间变化。前者约为 2 倍标准 96 DPI 桌面分辨率,而后者勉强超过标准 96 DPI 桌面分辨率。
1 Issues with High DPI (高DPI问题)
  • High DPI Displays cause a number of issues for existing applications:
  • 高DPI显示会给现有应用程序带来许多问题:
    • Applications using UI designs with fixed coordinates look small. The combination of font size specification in points and other sizes in pixels is particularly problematic since points are independent of the monitor resolution. For example, a frame of 40x20 pixels around the text “hello” using a 12pt font looks correct on low resolution monitors, but the frame will be too small on high DPI monitors, causing the text to be clipped.
    • 使用固定坐标的UI设计的应用程序看起来很小。以点为单位的字体大小规范和其他大小(以像素为单位)的组合尤其成问题,因为点与显示器的分辨率无关。例如,40x20像素的窗口中使用12pt字体大小的文本“hello”在低分辨率显示器上看起来是正确的,但是在高DPI显示器上窗口太小,从而导致文本被剪裁。
    • Applications must adapt to situations where users have multiple displays with varying resolution. For example, they might use a 4K monitor for the document window of an image editor and a low resolution monitor for the tool box.
    • 应用程序必须适应用户有多个分辨率不同的显示器的情况。例如,他们可能使用4K显示器作为图像编辑器的文档窗口,而低分辨率显示器用于工具箱。
  • The traditional approach to supporting high DPI has been one where Qt scaled fonts automatically, and then provided a DPI value that application code could use to scale the rest of the UI.
  • 支持高DPI的传统方法是Qt自动缩放字体,然后提供DPI值,应用程序代码可以使用它来缩放UI的其余部分。
2 Qt High DPI Support Overview (Qt 高DPI支持概述)
  • Qt supports a high DPI mode where the main coordinate system is virtualized and made independent of the display pixel density. This mode is implemented by some operating systems (macOS, iOS). In addition, Qt contains an implementation which may be used where operating system support is missing.
  • Qt支持高DPI模式,其中主坐标系被虚拟化,并且独立于显示像素密度。此模式由某些操作系统(macOS、iOS)实现。此外,Qt还包含一个在缺少操作系统支持的情况下使用的实现。
  • Geometry is now specified in device independent pixels. This includes widget and item geometry, event geometry, desktop, window and screen geometry, and animation velocities. Rendered output is in device pixels, which corresponds to the display resolution. The ratio between the device independent and device pixel coordinate systems is the devicePixelRatio.
  • Geometry现在以与设备无关的像素指定。这包括控件和子控件geometry, 事件geometry, 桌面, 窗口和屏幕geometry, 以及动画速度。渲染输出以设备像素表示,对应于显示分辨率。设备独立和设备像素坐标系之间的比率为devicePixelRatio。
  • Applications mostly work with device independent pixels. Notable exceptions are OpenGL and code that works with raster graphics.
  • 应用程序大多使用与设备无关的像素。值得注意的例外是OpenGL和处理光栅图形的代码。
3 Operating System Support (操作系统支持)
  • The operating systems supported by Qt offer the following support for high DPI displays: * Qt支持的操作系统为高DPI显示提供以下支持:
  • macOS and iOS
    • The Apple platforms implement scaling and coordinate system virtualization in the in the operating system. Normally, no special configuration is required.

    • 苹果平台在操作系统中实现了缩放和坐标系虚拟化。通常,不需要特殊配置。

    • Note: On macOS, high-DPI support is enabled by settings in the Info.plist file. Make sure they are present.

    • 注意:在macOS上,高DPI支持通过设置Info.plist文件,确保它们存在。

          ```
          <key>NSPrincipalClass</key>
          <string>NSApplication</string>
          <key>NSHighResolutionCapable</key>
          <string>True</string>
          
          ```
      
    • Never versions of qmake will generate Info.plist’s with the NSPrincipalClass key, which is sufficient since NSHighResolutionCapable is true by default.

    • qmake的任何版本都不会使用NSPrincipalClass密钥生成Info.plist,这是足够的,因为默认情况下NSHighResolutionCapable为true。

    • Note: macOS and iOS may apply further virtualization such that device pixels do not correspond 1:1 to display pixels. This happens on the iPhone 6+ and on macOS configured with ‘display scaling’ enabled.

    • 注意:macOS和iOS可能会应用进一步的虚拟化,使得设备像素与显示像素的比例不是1:1。这发生在配置了“display scaling”功能的iphone6+和macOS上。

  • Microsoft Windows
    • Scaling (缩放)
      • The user can choose a scaling factor from the control panel or via context menu. This works by making the functions for querying the system metrics return different values for standard font sizes, sizes of window borders, and so on. It does not perform any actual scaling.
      • 用户可以从控制面板或通过上下文菜单选择缩放因子。这是通过使查询系统度量的函数返回标准字体大小、窗口边框大小等的不同值来实现的。它不执行任何实际缩放。
    • DPI Awareness (DPI 感知)
      • An application on Windows can assume one of the following levels of “DPI Awareness”:

      • 在Windows中一个应用程序能声明以下DPI感知级别:

        DPI Awareness LevelMeaning
        DPI Unaware                                                                                                                                                                                This level has been introduced in Windows Vista. Windows will pretend to the application that it is running on a standard display of 96 DPI of 1920x1080 and scale the application accordingly. It is intended to accommodate older applications designed for low DPI displays. Some artifacts may result from this type of scaling.
        System-DPI AwareThis level has been introduced in Windows Vista. It differs from Per-Monitor DPI Aware only when multiple monitors are connected. Windows will calculate a scaling suitable for all connected monitors.
        Per-Monitor DPI AwareThis level has been introduced in Windows 8.1. Windows does not perform any scaling at all.
        DPI Awareness LevelMeaning
        DPI Unaware                                                                                                                                                                                此级别已在Windows Vista中引入。Windows将假装应用程序在标准的96dpi 1920x1080显示器上运行,并相应地缩放应用程序。它旨在适应为低DPI显示器设计的旧应用程序。这种类型缩放可能导致某些artifacts(瑕疵?)。
        System-DPI Aware此级别已在Windows Vista中引入。仅当多个监视器连接时它与Per-Monitor DPI Aware不同。Windows将计算适用于所有连接监视器的缩放值。
        Per-Monitor DPI Aware此级别已在Windows 8.1中引入。Windows根本不执行任何缩放。
      • Qt applications by default are Per-Monitor DPI Aware on Windows 8.1 or System-DPI Aware on older versions of Windows. As of Qt 5.4, the level can be specified by passing a parameter to the platform plugin (see Using qt.conf):

      • 默认情况下,Qt应用程序在windows8.1上是 Per-Monitor DPI Aware,在旧版本的Windows上是System-DPI Aware。从qt5.4开始,可以通过向平台插件传递一个参数来指定级别(参见使用qt.conf):

        • < application > -platform windows:dpiawareness=0,1,2
4 High DPI Support in Qt (Qt中高DPI支持)
  • Ability to provide pixmaps or artwork for high resolution: see “Drawing High Resolution Versions of Pixmaps and Images.”
  • 提供高分辨率的pixmaps或图片的能力: 查看 “Drawing High Resolution Versions of Pixmaps and Images.”
  • Qt 5.6 supports cross-platform high-DPI scaling for legacy applications, similar to the scaling done natively by macOS. This allows applications written for low-DPI screens to run unchanged on high-DPI devices. This feature is opt-in, and can be enabled by the following environment variables:
  • qt5.6支持遗留应用程序的跨平台高DPI扩展,类似于macOS本机进行的缩放。这允许为低DPI屏幕编写的应用程序在高DPI设备上不变地运行。此功能是可选的,可以通过以下环境变量启用:
    • QT_AUTO_SCREEN_SCALE_FACTOR [boolean] enables automatic scaling, based on the pixel density of the monitor. This will not change the size of point sized fonts, since point is a physical unit of measure. Multiple screens may get different scale factors.
    • QT_AUTO_SCREEN_SCALE_FACTOR [boolean] 根据显示器的像素密度启用自动缩放。这不会改变点sized fonts的大小,因为点是一个物理度量单位。多个屏幕可能得到不同的缩放因子。
    • QT_SCALE_FACTOR [numeric] defines a global scale factor for the whole application, including point sized fonts.
    • QT_SCALE_FACTOR [numeric] 为整个应用程序定义全局缩放因子,包括点sized fonts。
    • QT_SCREEN_SCALE_FACTORS [list] specifies scale factors for each screen. This will not change the size of point sized fonts. This environment variable is mainly useful for debugging, or to work around monitors with wrong EDID information(Extended Display Identification Data).
    • QT_SCREEN_SCALE_FACTORS [list] 指定每个屏幕的比例因子。这不会更改点sized fonts的大小。此环境变量主要用于调试或处理具有错误EDID信息(扩展显示标识数据)的显示器。
      • The format can be either a semicolon-separated list of scale factors in the same order as QGuiApplication::screens(), or a semicolon-separated list of name=value pairs, where name is the same as QScreen::name().
      • 格式可以是以分号分隔的缩放因子列表,其顺序与QGuiApplication::screens()相同,也可以是以分号分隔的name-value键值对列表,其中name与QScreen::name()相同。
    • While the macOS style fully supports high-DPI, the Windows desktop style currently has some limitations with certain scale factors. In these cases, consider using the Fusion style instead, which aims to support high-DPI in all cases.
    • 虽然macOS风格完全支持高DPI,但Windows桌面风格目前在某缩放因子上有一些限制。在这些情况下,考虑改用Fusion样式,其目的是在所有情况下都支持高DPI。
    • Note: Non-integer scale factors may cause significant scaling/painting artifacts.
    • 注意:非整数缩放因子可能会导致严重的缩放/绘制瑕疵。
  • The application attribute Qt::AA_EnableHighDpiScaling, introduced in Qt 5.6, enables automatic scaling based on the pixel density of the monitor.
  • Qt 5.6中引入的应用程序属性Qt::AA_EnableHighDpiScaling可以根据显示器的像素密度自动缩放。
  • The application attribute Qt::AA_DisableHighDpiScaling, introduced in Qt 5.6, turns off all scaling. This is intended for applications that need to use actual window system coordinates, regardless of environment variables. This attribute takes priority over Qt::AA_EnableHighDpiScaling.
  • Qt 5.6中引入的应用程序属性Qt::AA_DisableHighDpiScaling关闭所有缩放。这适用于需要使用实际窗口系统坐标的应用程序,而不考虑环境变量。此属性的优先级高于Qt::AA_EnableHighDpiScaling。
  • An experimental implementation of high-DPI scaling was introduced in Qt 5.4. It was enabled by the environment variable QT_DEVICE_PIXEL_RATIO, which could be set to a numerical scale factor or “auto”. This variable is deprecated in Qt 5.6.
  • qt5.4中介绍了一个高DPI缩放的实验实现。它是由环境变量QT_DEVICE_PIXEL_RATIO启用的,它可以设置为数字缩放因子或“auto”。Qt5.6中不推荐使用此变量。
5 Migration of Existing Applications(迁移现有应用程序)
  • In order to get an application designed for low DPI values running on a high resolution monitors quickly, consider one of the scaling options (let the application run as DPI Unaware on Windows or set the environment variable QT_AUTO_SCREEN_SCALE_FACTOR to “1”. These options may incur some scaling or painting artifacts, though.
  • 为了使设计用于低DPI值的应用程序快速在高分辨率显示器上运行,请考虑其中一个缩放选项(让应用程序在Windows上以DPI不知道的方式运行,或者将环境变量QT_AUTO_SCREEN_SCALE_FACTOR设置为“1”。不过,这些选项可能会产生一些缩放或绘制瑕疵。
  • In the longer term, the application should be adapted to run unmodified:
  • 从长远来看,应用程序应进行调整以不修改地运行:
    • Always use the qreal versions of the QPainter drawing API.
    • 始终使用QPainter绘图API的qreal版本。
    • Size windows and dialogs in relation to the screen size.
    • 根据屏幕大小调整窗口和对话框的大小。
    • Replace hard-coded sizes in layouts and drawing code by values calculated from font metrics or screen size.
    • 将布局和图形代码中的硬编码大小替换为根据字体指标或屏幕大小计算出的值。
6 Glossary Of High DPI Terms (术语表)
TermDefinition
Device Independent PixelsPixels used by application (user space), subject to scaling by the operating system or Qt.
Device PixelsPixels of the display device.
Device Pixel RatioScale factor applied by the operating system or Qt.
Logical DPIResolution used for converting font sizes defined in points to font sizes in pixels. Typically one of the standard values 96, 128, … 192.
Physical DPIPhysical resolution obtained by dividing the size of the monitor by the number of pixels.
Retina DisplaySee Wikipedia on Retina Displays
User SpaceThe coordinate space the application uses (Device Independent Pixels).
TermDefinition
Device Independent Pixels应用程序(用户空间)使用的像素,受操作系统或Qt缩放影响。
Device Pixels显示设备的像素。
Device Pixel Ratio操作系统或Qt应用的缩放因子
Logical DPI用于将以点为单位定义的字体大小转换为以像素为单位的字体大小的分辨率。通常为标准值96,128。。192之一
Physical DPI通过将显示器的大小除以像素数获得的物理分辨率。
Retina Display查看 “Wikipedia on Retina Displays”
User Space应用程序使用的坐标空间(Device Independent Pixels)。
三 官网
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值