How to hide a QML Window when opening a other QML Window

喜夏-厌秋 提交于 2020-01-05 02:57:42

问题


I need to hide The QML Window when opening the another QML Window while clicking the button,I use Loader to open the another QML Window and its only hide the QML form components not QML Window,but I currently use window component to opens the QML Window

Here is my code :

Button {
        id: button2
        x: 19
        y: 54
        width: 114
        height: 25
        text: qsTr("DIFF-R")
        style: ButtonStyle {
            background: Rectangle {
                implicitWidth: 10
                implicitHeight: 25
                border.width: control.activeFocus ? 2 : 1
                border.color: "#555"
                radius: 10
                gradient: Gradient {
                    GradientStop { position: 0 ; color: control.pressed ? "#ddd" : "#fff" }
                    GradientStop { position: 1 ; color: control.pressed ? "#8ad993" : "#528dc8" }

                }
    }
}
        onClicked:{ 
                    /*pagesource.source="screen2.qml"
            button1.visible="false"
            button2.visible="false"
            text1.visible="false"
            text2.visible="false"
            text3.visible="false"
            text4.visible="false"
            textField1.visible="false"
            textField2.visible="false"
            textField3.visible="false"
            image1.visible="false"*/ 
            var component = Qt.createComponent("screen2.qml")
            var window    = component.createObject(root)
            window.show("screen2.qml") }

The above code only navigates the QML Window while the Button is clicked whereas I need to Hide the QML Window.


回答1:


I see no code when you hide main window. Please, read this article since your code say nothing about the problem.

This is small example when main window hides when popup shows. May be it can be useful for you.

Window {
    id: mainWindow
    title: "Main window"
    width: 600
    height: 600
    visible: true
    flags: Qt.Dialog
    modality: Qt.ApplicationModal

    Component {
        id:  popupWindow
        Window {
            title: "Popup window"
            width: 400
            height: 400
            visible: true
            flags: Qt.Dialog
            modality: Qt.ApplicationModal
            Text {
                anchors.centerIn: parent
                text: "Close me to show main window"
            }
        }
    }

    Button {
        anchors.centerIn: parent
        text: "Show popup window"
        onClicked: {
            var window = popupWindow.createObject(mainWindow);
            mainWindow.hide();
            conn.target = window;
        }
    }

    Connections {
        id: conn
        onVisibleChanged: {
            mainWindow.show();
        }
    }
}


来源:https://stackoverflow.com/questions/30271781/how-to-hide-a-qml-window-when-opening-a-other-qml-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!