aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2026-06-08 10:29:05 +0200
committerAlbert Astals Cid <aacid@kde.org>2026-09-28 21:01:19 +0000
commit0136bdc2f3ca34c60e4d2c13c020175202523344 (patch)
tree983ee611b6966dc20c79af16cc8258487fa676d5
parent83d091dcb160d3f0c4a8bc9df8b8a9a934ac82a1 (diff)
Expose 4 QScreen properties to QML
Task-number: QTBUG-147270 Change-Id: I33c6fc8cc823c1e15fa0451ad1b213aa4471f39e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
-rw-r--r--src/quick/items/qquickscreen.cpp76
-rw-r--r--src/quick/items/qquickscreen_p.h14
-rw-r--r--tests/auto/quick/qquickscreen/data/screen.qml6
-rw-r--r--tests/auto/quick/qquickscreen/tst_qquickscreen.cpp8
4 files changed, 101 insertions, 3 deletions
diff --git a/src/quick/items/qquickscreen.cpp b/src/quick/items/qquickscreen.cpp
index 522b3af957..357720f6b1 100644
--- a/src/quick/items/qquickscreen.cpp
+++ b/src/quick/items/qquickscreen.cpp
@@ -190,6 +190,37 @@ QT_BEGIN_NAMESPACE
\sa primaryOrientation, QWindow::contentOrientation()
*/
/*!
+ \qmlattachedproperty rect Screen::geometry
+ \readonly
+ \since 6.13
+
+ This property holds the screen's geometry in pixels.
+*/
+/*!
+ \qmlattachedproperty rect Screen::availableGeometry
+ \readonly
+ \since 6.13
+
+ This property holds the screen's available geometry in pixels, excluding
+ window manager reserved areas such as task bars and system menus.
+*/
+/*!
+ \qmlattachedproperty rect Screen::desktopGeometry
+ \readonly
+ \since 6.13
+
+ This property holds the geometry of the virtual desktop in pixels.
+*/
+/*!
+ \qmlattachedproperty rect Screen::availableDesktopGeometry
+ \readonly
+ \since 6.13
+
+ This property holds the available geometry of the virtual desktop in
+ pixels, excluding window manager reserved areas such as task bars and
+ system menus.
+*/
+/*!
\qmlattachedmethod int Screen::angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b)
Returns the rotation angle, in degrees, between the specified screen
@@ -307,6 +338,34 @@ int QQuickScreenInfo::virtualY() const
return m_screen->geometry().topLeft().y();
}
+QRect QQuickScreenInfo::geometry() const
+{
+ if (!m_screen)
+ return {};
+ return m_screen->geometry();
+}
+
+QRect QQuickScreenInfo::availableGeometry() const
+{
+ if (!m_screen)
+ return {};
+ return m_screen->availableGeometry();
+}
+
+QRect QQuickScreenInfo::desktopGeometry() const
+{
+ if (!m_screen)
+ return {};
+ return m_screen->virtualGeometry();
+}
+
+QRect QQuickScreenInfo::availableDesktopGeometry() const
+{
+ if (!m_screen)
+ return {};
+ return m_screen->availableVirtualGeometry();
+}
+
void QQuickScreenInfo::setWrappedScreen(QScreen *screen)
{
if (screen == m_screen)
@@ -324,6 +383,7 @@ void QQuickScreenInfo::setWrappedScreen(QScreen *screen)
if (!oldScreen || screen->geometry() != oldScreen->geometry()) {
emit virtualXChanged();
emit virtualYChanged();
+ emit geometryChanged();
}
if (!oldScreen || screen->size() != oldScreen->size()) {
emit widthChanged();
@@ -341,15 +401,21 @@ void QQuickScreenInfo::setWrappedScreen(QScreen *screen)
emit orientationChanged();
if (!oldScreen || screen->primaryOrientation() != oldScreen->primaryOrientation())
emit primaryOrientationChanged();
- if (!oldScreen || screen->availableVirtualGeometry() != oldScreen->availableVirtualGeometry())
+ if (!oldScreen || screen->availableGeometry() != oldScreen->availableGeometry())
+ emit availableGeometryChanged();
+ if (!oldScreen
+ || screen->virtualGeometry() != oldScreen->virtualGeometry()
+ || screen->availableVirtualGeometry() != oldScreen->availableVirtualGeometry()) {
emit desktopGeometryChanged();
+ }
+ if (!oldScreen || screen->availableVirtualGeometry() != oldScreen->availableVirtualGeometry())
+ emit availableDesktopGeometryChanged();
if (!oldScreen || screen->logicalDotsPerInch() != oldScreen->logicalDotsPerInch())
emit logicalPixelDensityChanged();
if (!oldScreen || screen->physicalDotsPerInch() != oldScreen->physicalDotsPerInch())
emit pixelDensityChanged();
if (!oldScreen || screen->devicePixelRatio() != oldScreen->devicePixelRatio())
emit devicePixelRatioChanged();
-
qmlobject_connect(screen, QScreen, SIGNAL(geometryChanged(QRect)),
this, QQuickScreenInfo, SIGNAL(widthChanged()));
qmlobject_connect(screen, QScreen, SIGNAL(geometryChanged(QRect)),
@@ -358,16 +424,22 @@ void QQuickScreenInfo::setWrappedScreen(QScreen *screen)
this, QQuickScreenInfo, SIGNAL(virtualXChanged()));
qmlobject_connect(screen, QScreen, SIGNAL(geometryChanged(QRect)),
this, QQuickScreenInfo, SIGNAL(virtualYChanged()));
+ qmlobject_connect(screen, QScreen, SIGNAL(geometryChanged(QRect)),
+ this, QQuickScreenInfo, SIGNAL(geometryChanged()));
qmlobject_connect(screen, QScreen, SIGNAL(orientationChanged(Qt::ScreenOrientation)),
this, QQuickScreenInfo, SIGNAL(orientationChanged()));
qmlobject_connect(screen, QScreen, SIGNAL(primaryOrientationChanged(Qt::ScreenOrientation)),
this, QQuickScreenInfo, SIGNAL(primaryOrientationChanged()));
qmlobject_connect(screen, QScreen, SIGNAL(virtualGeometryChanged(QRect)),
this, QQuickScreenInfo, SIGNAL(desktopGeometryChanged()));
+ qmlobject_connect(screen, QScreen, SIGNAL(virtualGeometryChanged(QRect)),
+ this, QQuickScreenInfo, SIGNAL(availableDesktopGeometryChanged()));
qmlobject_connect(screen, QScreen, SIGNAL(logicalDotsPerInchChanged(qreal)),
this, QQuickScreenInfo, SIGNAL(logicalPixelDensityChanged()));
qmlobject_connect(screen, QScreen, SIGNAL(physicalDotsPerInchChanged(qreal)),
this, QQuickScreenInfo, SIGNAL(pixelDensityChanged()));
+ qmlobject_connect(screen, QScreen, SIGNAL(availableGeometryChanged(QRect)),
+ this, QQuickScreenInfo, SIGNAL(availableGeometryChanged()));
}
QScreen *QQuickScreenInfo::wrappedScreen() const
diff --git a/src/quick/items/qquickscreen_p.h b/src/quick/items/qquickscreen_p.h
index 1e5751285e..da72374ca4 100644
--- a/src/quick/items/qquickscreen_p.h
+++ b/src/quick/items/qquickscreen_p.h
@@ -20,6 +20,7 @@
#include <QtQuick/private/qtquickglobal_p.h>
#include <QtCore/qpointer.h>
+#include <QtCore/qrect.h>
QT_BEGIN_NAMESPACE
@@ -48,6 +49,12 @@ class Q_QUICK_EXPORT QQuickScreenInfo : public QObject
Q_PROPERTY(int virtualX READ virtualX NOTIFY virtualXChanged REVISION(2, 3) FINAL)
Q_PROPERTY(int virtualY READ virtualY NOTIFY virtualYChanged REVISION(2, 3) FINAL)
+
+ Q_PROPERTY(QRect geometry READ geometry NOTIFY geometryChanged REVISION(6, 13) FINAL)
+ Q_PROPERTY(QRect availableGeometry READ availableGeometry NOTIFY availableGeometryChanged REVISION(6, 13) FINAL)
+ Q_PROPERTY(QRect desktopGeometry READ desktopGeometry NOTIFY desktopGeometryChanged REVISION(6, 13) FINAL)
+ Q_PROPERTY(QRect availableDesktopGeometry READ availableDesktopGeometry NOTIFY availableDesktopGeometryChanged REVISION(6, 13) FINAL)
+
QML_NAMED_ELEMENT(ScreenInfo)
QML_ADDED_IN_VERSION(2, 3)
QML_UNCREATABLE("ScreenInfo can only be used via the attached property, or by retrieving it from Application's screens property.")
@@ -70,6 +77,10 @@ public:
Qt::ScreenOrientation orientation() const;
int virtualX() const;
int virtualY() const;
+ QRect geometry() const;
+ QRect availableGeometry() const;
+ QRect desktopGeometry() const;
+ QRect availableDesktopGeometry() const;
void setWrappedScreen(QScreen *screen);
QScreen *wrappedScreen() const;
@@ -89,6 +100,9 @@ Q_SIGNALS:
void orientationChanged();
Q_REVISION(2, 3) void virtualXChanged();
Q_REVISION(2, 3) void virtualYChanged();
+ Q_REVISION(6, 13) void geometryChanged();
+ Q_REVISION(6, 13) void availableGeometryChanged();
+ Q_REVISION(6, 13) void availableDesktopGeometryChanged();
protected:
QPointer<QScreen> m_screen;
diff --git a/tests/auto/quick/qquickscreen/data/screen.qml b/tests/auto/quick/qquickscreen/data/screen.qml
index 5ae008df17..c6c354d8be 100644
--- a/tests/auto/quick/qquickscreen/data/screen.qml
+++ b/tests/auto/quick/qquickscreen/data/screen.qml
@@ -1,5 +1,5 @@
import QtQuick 2.0
-import QtQuick.Window 2.3 as Window
+import QtQuick.Window 6.13 as Window
Item {
width: 100
@@ -11,6 +11,10 @@ Item {
property real devicePixelRatio: Window.Screen.devicePixelRatio
property int vx: Window.Screen.virtualX
property int vy: Window.Screen.virtualY
+ property rect screenGeometry: Window.Screen.geometry
+ property rect screenAvailableGeometry: Window.Screen.availableGeometry
+ property rect desktopGeometry: Window.Screen.desktopGeometry
+ property rect availableDesktopGeometry: Window.Screen.availableDesktopGeometry
property int screenCount: Qt.application.screens.length
diff --git a/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp b/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp
index 74d50eed22..11c4c5e119 100644
--- a/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp
+++ b/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp
@@ -49,6 +49,10 @@ void tst_qquickscreen::basicProperties()
QVERIFY(screen->devicePixelRatio() >= 1.0);
QCOMPARE(screen->geometry().x(), root->property("vx").toInt());
QCOMPARE(screen->geometry().y(), root->property("vy").toInt());
+ QCOMPARE(screen->geometry(), root->property("screenGeometry").toRect());
+ QCOMPARE(screen->availableGeometry(), root->property("screenAvailableGeometry").toRect());
+ QCOMPARE(screen->virtualGeometry(), root->property("desktopGeometry").toRect());
+ QCOMPARE(screen->availableVirtualGeometry(), root->property("availableDesktopGeometry").toRect());
QVERIFY(root->property("screenCount").toInt() == QGuiApplication::screens().size());
}
@@ -105,6 +109,10 @@ void tst_qquickscreen::fullScreenList()
QCOMPARE(screenList[i]->devicePixelRatio(), info->devicePixelRatio());
QCOMPARE(screenList[i]->geometry().x(), info->virtualX());
QCOMPARE(screenList[i]->geometry().y(), info->virtualY());
+ QCOMPARE(screenList[i]->geometry(), info->geometry());
+ QCOMPARE(screenList[i]->availableGeometry(), info->availableGeometry());
+ QCOMPARE(screenList[i]->virtualGeometry(), info->desktopGeometry());
+ QCOMPARE(screenList[i]->availableVirtualGeometry(), info->availableDesktopGeometry());
}
}