【发布时间】:2014-12-18 17:02:04
【问题描述】:
有Qt.quit()退出应用程序,但我只想退出当前屏幕,这应该让我回到父屏幕。我该怎么做?
Rectangle {
id: page
visible: true
width: 360
height: 480
Button {
width: 150
height: 50
text: "Parent"
onClicked: {
console.log("Parent pressed")
//? how to exit this screen here?
}
}
}
这是 Folibis 回答后的新代码。
import QtQuick 2.3
import QtQuick.Window 2.2
Window {
visible: true
width: 360
height: 360
property bool isClose: false
MouseArea {
anchors.fill: parent
onClicked: {
if(isClose)
Qt.quit();
else
Page2.show() //subWindow.show();
isClose = true;
}
}
Text {
text: qsTr("Hello World")
anchors.centerIn: parent
}
}
窗口位于新的 qml 文件中,现在名为 Page2.qml
import QtQuick 2.0
import QtQuick.Window 2.2
Window {
id: subWindow
visible: false
width: 400
height: 400
flags: Qt.Dialog
Text {
anchors.centerIn: parent
text: "Click me to close the subwindow"
}
MouseArea {
anchors.fill: parent
onClicked: subWindow.close();
}
}
问题是如何从 main.qml 调用 Page2.qml?
【问题讨论】:
-
也许只是
page.visible = false? -
只有
rectangle在同一个文件中才有效,我想从另一个qml文件返回。 -
查看 StackView:qt-project.org/doc/qt-5-snapshot/…