Details
-
Bug
-
Resolution: Incomplete
-
Not Evaluated
-
None
-
5.15.0
-
None
Description
According to the docs centering into a custom parent should be possible.
https://doc.qt.io/qt-5/qml-qtquick-controls2-popup.html#anchors.centerIn-prop
See video and example project.
import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Controls.Material 2.12 import QtQuick.Controls 2.12 import QtQuick.Controls.Material.impl 2.12 Window { width: 640 height: 480 visible: true title: qsTr("Hello World") Component.onCompleted: popup.open() Popup { id: popup dim: true modal: true width: 300 height: 300 anchors.centerIn: parent Button { anchors.centerIn: parent highlighted: true text: "Open" onClicked: drawer.open() } Rectangle { id: wrapper color: "gray" height: 50 anchors { right: parent.right left: parent.left bottom: parent.bottom } Text { text: qsTr("Should center here") anchors.centerIn: parent color: "white" } Drawer { id: drawer modal: false dim: false interactive: false height: 40 width: 300 edge: Qt.BottomEdge // ###### Popup documentation: anchors.centerIn: parent // Also not working // anchors.centerIn: wrapper // This generates // qrc:/main.qml:45:13: QML Drawer: Popup can only be centered within its immediate parent or Overlay.overlay // but it should be the same as parent // Anchors provide a way to position an item by specifying its relationship with other items. // A common use case is to center a popup within its parent. One way to do this is with the x and y properties. Anchors offer a more convenient approach: // Pane { // // ... // Popup { // anchors.centerIn: parent // } // } Button { onClicked: drawer.close() text: qsTr("close") anchors.centerIn: parent } background: Rectangle { radius: 4 color: Material.color(Material.LightBlue) layer.enabled: true layer.effect: ElevationEffect { elevation: 6 } } } } } }