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

Drawer/Popup does not center in parent

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Need More Info
    • Priority: Not Evaluated
    • Resolution: Incomplete
    • Affects Version/s: 5.15.0
    • Fix Version/s: None
    • Component/s: Quick: Controls 2
    • Labels:
    • Platform/s:
      Windows

      Description

      YgyFYwiDTE.mp4

       

      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
                          }
                      }
                  }
              }
          }
      }
      

        Attachments

        1. YgyFYwiDTE.mp4
          57 kB
        2. QMLDrawerPositionBug.zip
          18 kB
        3. 7nFwL4DPUo.gif
          7nFwL4DPUo.gif
          136 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            qt.team.quick.subscriptions Qt Quick and Widgets Team
            Reporter:
            kelteseth Elias Steurer
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes