简体   繁体   中英

QML Dialog positioning in ApplicationWindow

I am finding it impossible to position a Dialog central to my ApplicationWindow in QT 5.12

import QtQuick 2.7
import QtQuick.Controls 2.2
import QtQuick.Dialogs 1.2


ApplicationWindow {

    id:mainApplicationWindow
    visible: true
    height: 500
    width: 500


  Item {
      anchors.centerIn: parent
      MainWindowMessageDialog{
          id: messageDialog
      }
  }

  Component.onCompleted: {
      messageDialog.open()
  }
}

With MainWindowMessageDialog.qml

import QtQuick 2.0
import QtQuick.Dialogs 1.2

Dialog {
    title: "There seems to be a problem"
    standardButtons: StandardButton.Ok
    onAccepted: {
        this.close()
    }
}

Gives me the image below. I've tried adding a fixed z position but nothing seems to shift the Dialog downwards into the window. I've tried MainWindowMessageDialog on its own outside of an Item. Nothing seems to shift it? Am I missing something?

在此处输入图片说明

This turned out to be an issue of modality.

https://bugreports.qt.io/browse/QTBUG-82737?jql=text%20~%20%22MessageDialog%22

Adding

modality: Qt.ApplicationModal

Did the trick

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM