응용 프로그램을 종료하는 Qt.quit()
이 있지만 현재 화면을 종료하고 부모 화면으로 돌아 가야합니다. 어떻게해야합니까?qml에서 단일 화면/페이지를 닫는 방법?
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
}
}
창
지금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를 호출하는 방법입니다 Page2.qml라는 이름의 새 QML 파일에?
어쩌면 단지'page.visible = FALSE '를 실행하는 코드를 :
예? – Chernobyl
'rectangle'이 같은 파일에있는 경우에만 작동합니다. 다른 qml 파일에서 반환하고 싶습니다. – zar
StackView 살펴보기 : https://qt-project.org/doc/qt-5-snapshot/qml-qtquick-controls-stackview.html – MrEricSir