Qt Quick SafeArea not working correctly on Android
-
Issue: On Android, SafeArea.margins seems to return zero, so the safe area fills the entire screen.
I am trying to create a Qt Quick mobile application using SafeArea to restrict the location of contents on the screen. It works well on desktop, but when I run it on my mobile device the margins provided by SafeArea either don't work, or return zero.
I have created an MWE using Qt 6.9.1 to demonstrate the problem. This MWE is based on the example provided in the SafeArea documentation. The full window is filled with the SunnyMorning (orange) gradient, while the safe area of the window is filled with the DustyGrass (green) gradient.
import QtQuick import QtQuick.Controls ApplicationWindow { width: 640 height: 480 visible: true flags: Qt.Window | Qt.ExpandedClientAreaHint | Qt.NoTitleBarBackgroundHint title: qsTr("Safe Area") topPadding: 0 Rectangle { id: parentItem gradient: Gradient.SunnyMorning anchors.fill: parent Rectangle { id: childItem gradient: Gradient.DustyGrass anchors { fill: parent topMargin: parent.SafeArea.margins.top leftMargin: parent.SafeArea.margins.left rightMargin: parent.SafeArea.margins.right bottomMargin: parent.SafeArea.margins.bottom } } } }
However, when running the application the safe area (DustyGrass) erroneously fills up the entire window and no SunnyMorning gradient is visible. The safe area should not overlap the status bar at the top, nor the controls at the bottom. Those areas should show the SunnyMorning gradient.
Question: How can I ensure that SafeArea behaves correctly on Android devices, respecting the status and navigation bars?
Note: I would have like to include images showing the problem, but they keep getting flagged as spam. To see the application output on desktop and mobile take a look at this post.
Android build info (possibly relevant):
- DANDROID_ABI: arm64-v8a
- DANDROID_NDK: 27.2.12479018
- DANDROID_PLATFORM: android-23
- Build-tools: 35.0.1
- SDK: android-35
-
-
-
you need Qt 6.9.3 with fixes to SafeArea on Android
https://bugreports.qt.io/browse/QTBUG-135808
https://bugreports.qt.io/browse/QTBUG-139690
BTW: the problem with SafeArea is 0 at startup on Android: workaround rotate to landscape and back. but this is fixed w 6.9.3 -
you need Qt 6.9.3 with fixes to SafeArea on Android
https://bugreports.qt.io/browse/QTBUG-135808
https://bugreports.qt.io/browse/QTBUG-139690
BTW: the problem with SafeArea is 0 at startup on Android: workaround rotate to landscape and back. but this is fixed w 6.9.3@ekkescorner In Qt Maintenance Tool I do not see 6.9.3. The newest options available to me are 6.9.2 and 6.10.0-rc. Would 6.9.2 be sufficient? How could I get 6.9.3 in another way?
-
6.9.3 will come out next week https://wiki.qt.io/Qt_6.9_Release