好的,你只需要创建一个对话框(或者看起来像一个对话框的组件),并且只想与主窗口和交互对话框窗口。
请尝试以下方法:
main.qml
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
ApplicationWindow {
id: rootWindow
visible: true
width: 640
height: 480
title: qsTr("Hello World")
color: "green"
Rectangle {
id: behind
anchors.fill: parent
color: Qt.rgba(0, 0, 0, 0.7)
visible: false
}
MouseArea {
enabled: behind.visible
anchors.fill: parent
onClicked: {
console.log("Root Window")
}
}
Button {
text: "Open Dialog"
onClicked: {
behind.visible = true;
var comp = Qt.createComponent("qrc:/MyDialog.qml");
// var comp = Qt.createComponent("qrc:/DialogQt.qml");
var obj1 = comp.createObject(rootWindow, {});
obj1.z = 2;
}
}
}
MyDialog.qml
import QtQuick 2.7
Rectangle {
id: modalWindow
width: 200
height: 200
color: "red"
anchors.centerIn: parent
MouseArea {
anchors.fill: parent
onClicked: {
console.log("Modal Window")
}
}
}
点击 '打开对话框' 按钮将创建并打开 '模式' 对话框主窗口组件的顶部。
当然,您必须调整“MyDialog.qml”文件以适合您自己的设计要求。
但是,使用此作为一个“真正的”对话也没有工作,(我)像通用已经在评论部分中指出:
DialogQt.qml
Dialog {
visible: true
title: "Blue sky dialog"
modality : Qt.ApplicationModal
contentItem: Rectangle {
color: "lightskyblue"
anchors.fill: parent
Text {
text: "Hello blue sky!"
color: "navy"
anchors.centerIn: parent
}
}
}
也许你可以用MouseArea过滤掉对话外的点击事件? – sk2212
@ sk2212:我认为这不会起作用。我希望使用它能够点击并与主窗口或浮动远程进行交互。基本上只是标准的工具窗口行为。 – MusiGenesis
嗯......你可以从你的窗口和对话框创建一个简单的截图吗?我仍然不明白你的观点。 – sk2212