aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols/doc/snippets
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2024-11-17 15:35:26 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2024-12-09 18:47:20 +0100
commit83d90845527799c78366c2b89e9c14bc35e88695 (patch)
tree2a333fe7c3ab59adede7083cef7d039030a55c5a /src/quickcontrols/doc/snippets
parent576e5fce84b0e554e16949e9e825144438b5acc8 (diff)
Teach ApplicationWindow about safe area margins
If the window has non-safe areas, as reflected by the window's safe area margins, ApplicationWindow will now automatically pad the content item accordingly, ensuring that the content item is within the safe area of the window. To implement this we piggy-back on QQuickControl, letting the control manage the size and position of the content item. This allows us to use the built in padding of QQuickControl to inset the content. Internally the item hierarchy of ApplicationWindow no longer represents the header, footer, and menu bar as children of the ApplicationWindow's content item, but rather as sibling items in the QQuickWindow content item, similar to the window's background item. Doing this is a slight behavior change, but for something that should have been an implementation detail as far as users are concerned. The content control and header, footer and menu bar now all live within the same root QQuickWindow::contentItem, which is a focus scope on its own. End users can override the automatic padding that we do for the contentItem by setting any of the four new padding properties that we expose, mirroring the properties on QQuickControl. [ChangeLog][Important Behavior Changes] The contentItem of ApplicationWindow is now automatically padded to account for safe area margins. To override the automatic padding, set the padding explicitly, via e.g. `topPadding: 0`. Task-number: QTBUG-125373 Change-Id: I986e425a7f316db244c7fc86283b8b333978e3ad Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/quickcontrols/doc/snippets')
-rw-r--r--src/quickcontrols/doc/snippets/qtquickcontrols-appwindow-safeareas.qml39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/quickcontrols/doc/snippets/qtquickcontrols-appwindow-safeareas.qml b/src/quickcontrols/doc/snippets/qtquickcontrols-appwindow-safeareas.qml
new file mode 100644
index 0000000000..05d2061ebd
--- /dev/null
+++ b/src/quickcontrols/doc/snippets/qtquickcontrols-appwindow-safeareas.qml
@@ -0,0 +1,39 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+import QtQuick
+import QtQuick.Controls
+
+//![0]
+ApplicationWindow {
+//![0]
+ flags: Qt.ExpandedClientAreaHint | Qt.NoTitleBarBackgroundHint
+ visible: true
+//![1]
+ // Remove automatic safe area padding
+ topPadding: 0
+
+ Flickable {
+ // Inset content by safe area margin
+ topMargin: SafeArea.margins.top
+//![1]
+ anchors.fill: parent
+
+ Rectangle {
+ id: rect
+ width: 1000
+ height: 1000
+ gradient: Gradient.DustyGrass
+ }
+
+ contentWidth: rect.width
+ contentHeight: rect.height
+
+ onTopMarginChanged: {
+ // Workaround for QTBUG-131478
+ contentY = -topMargin
+ }
+//![2]
+ }
+}
+//![2]