Details
-
Bug
-
Resolution: Invalid
-
P2: Important
-
None
-
5.12.3
-
iPhone X
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.