Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt Quick SafeArea not working correctly on Android
Forum Updated to NodeBB v4.3 + New Features

Qt Quick SafeArea not working correctly on Android

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
qt 6.9.1androidsafeareaquick2
4 Posts 2 Posters 48 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dan_v
    wrote last edited by Dan_v
    #1

    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
    1 Reply Last reply
    0
    • D Dan_v marked this topic as a regular topic
    • D Dan_v marked this topic as a question
    • ekkescornerE Offline
      ekkescornerE Offline
      ekkescorner
      Qt Champions 2016
      wrote last edited by
      #2

      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

      ekke ... Qt Champion 2016 | 2024 ... mobile business apps
      5.15 --> 6.9 https://t1p.de/ekkeChecklist
      QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

      D 1 Reply Last reply
      1
      • ekkescornerE ekkescorner

        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

        D Offline
        D Offline
        Dan_v
        wrote last edited by
        #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?

        1 Reply Last reply
        0
        • ekkescornerE Offline
          ekkescornerE Offline
          ekkescorner
          Qt Champions 2016
          wrote last edited by
          #4

          6.9.3 will come out next week https://wiki.qt.io/Qt_6.9_Release

          ekke ... Qt Champion 2016 | 2024 ... mobile business apps
          5.15 --> 6.9 https://t1p.de/ekkeChecklist
          QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved