打开另一个QML窗口时如何隐藏QML窗口 [英] How to hide a QML Window when opening a other QML Window

查看:1026
本文介绍了打开另一个QML窗口时如何隐藏QML窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在单击按钮的同时打开另一个QML窗口时隐藏QML窗口,我使用Loader打开另一个QML窗口,并且它仅隐藏QML表单组件而不是QML窗口,但是我目前正在使用窗口组件来打开QML窗口

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

这是我的代码:

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") }

上面的代码仅在单击Button的同时导航QML窗口,而我需要隐藏QML窗口.

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

推荐答案

隐藏主窗口时看不到任何代码.请阅读本文,因为您的代码没有说明该问题.

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();
        }
    }
}

这篇关于打开另一个QML窗口时如何隐藏QML窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆