Screen QML Type

屏幕附加对象提供有关项目或窗口所显示屏幕的信息。更多

Import Statement: import QtQuick

附加属性

附加方法

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

详细说明

在组件完成后,Screen 附件对象在 Item 或 Item 派生类型中有效。在这些项目中,它指的是项目当前显示的屏幕。

组件完成后,附加对象在 Window 或 Window 派生类型中也有效。在这种情况下,它指的是创建窗口的屏幕。一般来说,最好从相关的项目访问屏幕,因为在多屏幕桌面电脑上,用户可以将窗口拖到跨越多个屏幕的位置。在这种情况下,一些项目会在一个屏幕上,而另一些则在另一个屏幕上。

要使用这种类型,需要用下面一行导入模块:

import QtQuick.Window 2.2

这是一个单独的导入,以便让你拥有一个不使用窗口系统功能的 QML 环境。

注意 Screen 类型在 Component.onCompleted 时无效,因为此时 Item 或 Window 还没有显示在屏幕上。

另请参阅 Qt Quick Examples - Window 和 Screen

附加属性文档

Screen.desktopAvailableHeight : int [read-only]

该属性包含组成虚拟桌面的屏幕集合的可用高度,单位为像素,不包括窗口管理器保留区域(如任务栏和系统菜单)。如果要将窗口定位在桌面底部,可以这样绑定:

y: Screen.desktopAvailableHeight - height

Screen.desktopAvailableWidth : int [read-only]

这包含组成虚拟桌面的屏幕集合的可用宽度,单位为像素,不包括窗口管理器保留区域(如任务栏和系统菜单)。如果要将窗口定位在桌面右侧,可以这样绑定:

x: Screen.desktopAvailableWidth - width

Screen.devicePixelRatio : real [read-only]

屏幕物理像素与设备无关像素之间的比例。

普通显示器的常用值为 1.0,苹果 "视网膜 "显示器的常用值为 2.0。


Screen.height : int [read-only]

屏幕高度(以像素为单位)。


Screen.manufacturer : string [read-only]

屏幕制造商。


Screen.model : string [read-only]

屏幕的型号。


Screen.name : string [read-only]

屏幕名称。


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

从窗口系统角度看屏幕的当前方向。

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

另请参阅 primaryOrientationQWindow::contentOrientation()。


Screen.pixelDensity : real [read-only]

每毫米物理像素数。


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

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

如果您正在设计一个根据设备方向改变布局的应用程序,您可能希望使用 primaryOrientation 来确定布局。这是因为在台式电脑上,当用户通过操作系统的控制面板旋转屏幕时,即使电脑不包含加速计,您也可以预期 primaryOrientation 会发生变化。同样,在大多数有加速度计的手持电脑上,操作系统会自动旋转整个屏幕,因此你也会看到 primaryOrientation 发生变化。


Screen.serialNumber : string [read-only]

屏幕的序列号。


Screen.virtualX : int [read-only]

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


Screen.virtualY : int [read-only]

屏幕在虚拟桌面内的 y 坐标。


Screen.width : int [read-only]

屏幕宽度(像素)。


附加方法文档

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

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


© 2025 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.