Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-76234

safeMargine does not return the correct value immediately

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • None
    • 5.12.3
    • QPA
    • iPhone X
    • iOS/tvOS/watchOS

    Description

      As it is suggested in QTBUG-64574, I created the following function in order to access device's safe area from QML.

      QVariantMap SafeMargins::getSafeAreaMargins(QQuickWindow *window)
      {
          QPlatformWindow *platformWindow = static_cast<QPlatformWindow *>(window->handle());
          QVariantMap map;
          ...
          QMargins margins = platformWindow->safeAreaMargins();
          map["top"] = margins.top();
          map["right"] = margins.right();
          map["bottom"] = margins.bottom();
          map["left"] = margins.left();
          qDebug() << margins;
          return map;
      }
      

      However, when switching the orientation of the phone, the getSafeMargin function still
      returns the old margins and it requires timer delay before requesting the new margins.

      Here's the log in case of 5 seconds delay

      2019-06-06 08:43:14.560154+0200 safeArea[5728:1593640] QMargins(0, 44, 0, 34)
      
      2019-06-06 08:43:14.560877+0200 safeArea[5728:1593640] [qml] safe margins direct = {"bottom":34,"left":0,"right":0,"top":44}
      
      2019-06-06 08:43:19.835085+0200 safeArea[5728:1593640] QMargins(44, 0, 44, 21)
      
      2019-06-06 08:43:19.835663+0200 safeArea[5728:1593640] [qml] safe margins delayed = {"bottom":21,"left":44,"right":44,"top":0}
      
      

      Sample code is attached.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            tpochep Timur Pocheptsov
            nagrohn Nahomi Gröhn (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes