本页内容

Screen QML Type

“Screen”关联对象提供有关显示某项或窗口的屏幕的信息。更多...

Import Statement: import QtQuick

关联属性

附带的方法

  • int angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b)

详细说明

“Screen”关联对象在组件初始化完成后,在“Item”或其派生类型内部有效。在这些项内部,它指代当前显示该项的屏幕。

该关联对象在 Window 或 Window 派生类型中,于组件完成之后同样有效。在此情况下,它指代创建该 Window 的屏幕。通常建议通过相关的 Item 来访问 Screen,因为在多屏台式计算机上,用户可能会将 Window 拖动到横跨多个屏幕的位置。 此时,部分 `Item` 将位于一个屏幕上,而其他 `Item` 则位于另一个屏幕上。

要使用此类型,您需要通过以下代码行导入该模块:

import QtQuick.Window 2.2

这是一个独立的导入,旨在允许您在无法访问窗口系统功能的情况下仍能构建 QML 环境。

请注意,在 Component.onCompleted 方法中“Screen”类型无效,因为此时 Item 或 Window 尚未在屏幕上显示。

另请参阅 《Qt Quick 示例——Window与Screen》。

附加属性文档

Screen.desktopAvailableHeight : int [read-only attached]

该参数表示构成虚拟桌面的屏幕集合的可用高度(以像素为单位),不包括窗口管理器预留的区域(如任务栏和系统菜单)。如果你想将一个窗口定位在桌面的底部,可以像这样进行绑定:

y: Screen.desktopAvailableHeight - height

Screen.desktopAvailableWidth : int [read-only attached]

该值表示构成虚拟桌面的所有屏幕的可用宽度(以像素为单位),不包括窗口管理器预留的区域(如任务栏和系统菜单)。如果你想将一个窗口定位在桌面的右侧,可以像这样进行绑定:

x: Screen.desktopAvailableWidth - width

Screen.devicePixelRatio : real [read-only attached]

屏幕上物理像素与设备独立像素之间的比例。

常见值为:普通显示屏为 1.0,Apple “视网膜”显示屏为 2.0。

Screen.height : int [read-only attached]

此处包含屏幕高度(以像素为单位)。

Screen.manufacturer : string [read-only attached]

该屏幕的制造商。

Screen.model : string [read-only attached]

该屏幕的型号。

Screen.name : string [read-only attached]

屏幕的名称。

Screen.orientation : Qt::ScreenOrientation [read-only attached]

该字段包含从窗口系统角度看屏幕的当前方向。

大多数移动设备和平板电脑都配备了加速度计传感器。窗口系统可能会根据设备持握方式自动旋转整个屏幕,或者通过设置手动旋转台式机显示器;在这种情况下,orientation 属性将会发生变化。

另请参阅 primaryOrientation 和QWindow::contentOrientation()。

Screen.pixelDensity : real [read-only attached]

每毫米的物理像素数。

Screen.primaryOrientation : Qt::ScreenOrientation [read-only attached]

该属性包含屏幕的主要方向。如果屏幕的高度大于宽度,则方向为 Qt.PortraitOrientation;否则为 Qt.LandscapeOrientation。

如果您正在设计一款会根据设备方向调整布局的应用程序,您可能需要使用 primaryOrientation 来确定布局。这是因为在台式计算机上,当用户通过操作系统的控制面板旋转屏幕时,即使计算机未配备加速度计,primaryOrientation 也会发生变化。 同样,在大多数配备加速度计的手持设备上,操作系统会自动旋转整个屏幕,因此你也会看到 `primaryOrientation` 发生变化。

Screen.serialNumber : string [read-only attached]

屏幕的序列号。

Screen.virtualX : int [read-only attached]

虚拟桌面中屏幕的x坐标。

Screen.virtualY : int [read-only attached]

虚拟桌面中屏幕的 y 坐标。

Screen.width : int [read-only attached]

该参数包含屏幕的宽度(以像素为单位)。

附带的方法文档

[attached] int angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b)

返回指定屏幕方向a 和b 之间的旋转角度(单位为度)。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.