Reputation: 1173
I try to put a button and click it will open a dialog, but my dialog open in ApplicationWindow
, not as a standalone windows?
Code
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Dialogs 1.2
import QtQuick.Controls 2.15
ApplicationWindow {
visible: true
id: root
Row {
Button {
width: root.width
height: 20
text: "bn"
onClicked: myDlg.open()
}
}
Dialog {
id: myDlg
title: "Rabbit"
Label {
anchors.fill: parent
text: "Rabbit"
}
standardButtons: Dialog.Ok
onAccepted: console.log("abc")
}
}
Upvotes: 0
Views: 536
Reputation: 243955
In qml there are different components with the same name in different modules, and that is what happens with Dialog:
In the case of the code provided by the OP, the Dialog belonging to the "Qt Quick Control 2" module is being used, and since it inherits from Popup
then it will be shown as an internal item to the window.
The solution is to use an alias to differentiate:
import QtQuick 2.15
import QtQuick.Controls 2.15 as QQC
import QtQuick.Dialogs 1.3 as QQD
QQC.ApplicationWindow {
id: root
visible: true
Row {
QQC.Button {
width: root.width
height: 20
text: "bn"
onClicked: myDlg.open()
}
}
QQD.Dialog {
id: myDlg
title: "Rabbit"
QQC.Label {
anchors.fill: parent
text: "Rabbit"
}
standardButtons: QQD.Dialog.Ok
onAccepted: console.log("abc")
}
}
Upvotes: 2