Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to make a window inactive?

How to make a window inactive?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
9 Posts 3 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Subuday
    wrote on last edited by
    #1

    Hi, I want to make a window in background inactive when the user start login window(white window on the screen). I don't wanna default window to hide, just user can't use it.

    0_1556442155409_Screenshot from 2019-04-28 12-02-01.png

    Here is my code:

    ApplicationWindow {
        id: startWindow
    
        width: 1000
        height: 700
        visible: true
    
        Material.theme: Material.Light
    
        flags: Qt.FramelessWindowHint
    
        property int previousX
        property int previousY
    
        Item {
            focus: true
            Keys.onPressed: {
                if (event.key === Qt.Key_Escape) { Qt.quit(); event.accepted = true }
            }
        }
    
    
        MouseArea {
            anchors.fill: parent
    
            onPressed: {
                previousX = mouseX
                previousY = mouseY
            }
    
            onMouseXChanged: {
                var dx = mouseX - previousX
                startWindow.setX(startWindow.x + dx)
            }
    
            onMouseYChanged: {
                var dy = mouseY - previousY
                startWindow.setY(startWindow.y + dy)
            }
        }
                NaviButton {
                    id: singUpButton
                    text: "SIGN UP"
    
                    onStateChanged: {
                        if(singUpButton.selected == true) {
                            pageInfoButton.selected = false
                            loginButton.selected = false
                            singUpButton.selected = false
                        }
                    }
           }
    }      
    
    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      You can try with window modality property.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      S 1 Reply Last reply
      3
      • dheerendraD dheerendra

        You can try with window modality property.

        S Offline
        S Offline
        Subuday
        wrote on last edited by
        #3

        @dheerendra said in How to make a window inactive?:

        You can try with window modality property.

        Could you explain, please?

        1 Reply Last reply
        0
        • Shrinidhi UpadhyayaS Offline
          Shrinidhi UpadhyayaS Offline
          Shrinidhi Upadhyaya
          wrote on last edited by
          #4

          Hi @Subuday , have a look at the sample code:-

           ApplicationWindow {
                  id: startWindow
          
                  width: 1000
                  height: 700
                  visible: true
                  modality: Qt.WindowModal  //####Use this property in your code.
                  [..]
                  [..]
          }  
          

          For more detailed explanation you can refer to the documentation[https://doc.qt.io/archives/qt-4.8/qt.html#WindowModality-enum]

          Shrinidhi Upadhyaya.
          Upvote the answer(s) that helped you to solve the issue.

          S 1 Reply Last reply
          4
          • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

            Hi @Subuday , have a look at the sample code:-

             ApplicationWindow {
                    id: startWindow
            
                    width: 1000
                    height: 700
                    visible: true
                    modality: Qt.WindowModal  //####Use this property in your code.
                    [..]
                    [..]
            }  
            

            For more detailed explanation you can refer to the documentation[https://doc.qt.io/archives/qt-4.8/qt.html#WindowModality-enum]

            S Offline
            S Offline
            Subuday
            wrote on last edited by
            #5

            @Shrinidhi-Upadhyaya said in How to make a window inactive?:

            Hi @Subuday , have a look at the sample code:-

             ApplicationWindow {
                    id: startWindow
            
                    width: 1000
                    height: 700
                    visible: true
                    modality: Qt.WindowModal  //####Use this property in your code.
                    [..]
                    [..]
            }  
            

            For more detailed explanation you can refer to the documentation[https://doc.qt.io/archives/qt-4.8/qt.html#WindowModality-enum]

            Unfortunately, I can still move the window on the background

            1 Reply Last reply
            0
            • Shrinidhi UpadhyayaS Offline
              Shrinidhi UpadhyayaS Offline
              Shrinidhi Upadhyaya
              wrote on last edited by
              #6

              Hi @Subuday , can you share the complete code,i mean the code for the background window also.

              Shrinidhi Upadhyaya.
              Upvote the answer(s) that helped you to solve the issue.

              S 1 Reply Last reply
              0
              • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

                Hi @Subuday , can you share the complete code,i mean the code for the background window also.

                S Offline
                S Offline
                Subuday
                wrote on last edited by
                #7

                @Shrinidhi-Upadhyaya said in How to make a window inactive?:

                Hi @Subuday , can you share the complete code,i mean the code for the background window also.

                Yes, of course

                startWindow

                import QtQuick 2.12
                import QtQuick.Window 2.12
                import QtQuick.Controls 2.5
                import QtQuick.Controls.Styles 1.4
                import QtQuick.Controls.Material 2.12
                import QtQuick.Layouts 1.3
                
                ApplicationWindow {
                    id: startWindow
                
                    width: 1000
                    height: 700
                    visible: true
                
                    signal openSignUpWindow()
                
                    modality: Qt.ApplicationModal
                
                    Material.theme: Material.Light
                
                    flags: Qt.FramelessWindowHint
                
                    property var loginWindow
                    property var signUpWindow
                
                    property int previousX
                    property int previousY
                
                    Connections {
                        target: loginWindow
                        onOpenSignUpWindow: {
                            var component = Qt.createComponent("qrc:/qml/SignUpWindow.qml")
                            signUpWindow = component.createObject(startWindow)
                            signUpWindow.show()
                        }
                    }
                
                    Item {
                        focus: true
                        Keys.onPressed: {
                            if (event.key === Qt.Key_Escape) { Qt.quit(); event.accepted = true }
                        }
                    }
                
                
                    MouseArea {
                        anchors.fill: parent
                
                        onPressed: {
                            previousX = mouseX
                            previousY = mouseY
                        }
                
                        onMouseXChanged: {
                            var dx = mouseX - previousX
                            startWindow.setX(startWindow.x + dx)
                        }
                
                        onMouseYChanged: {
                            var dy = mouseY - previousY
                            startWindow.setY(startWindow.y + dy)
                        }
                    }
                
                
                    Rectangle {
                        id: frame
                
                        height: 24
                        width: startWindow.width
                
                        RowLayout {
                            anchors.top: parent.top
                            anchors.right: parent.right
                            anchors.rightMargin: 8
                
                            Image {
                                source: "qrc:/icons/Icons/minimize.png"
                
                                MouseArea {
                                    anchors.fill: parent
                
                                    onClicked: {
                                        startWindow.showMinimized()
                                    }
                                }
                            }
                
                            Image {
                                source: "qrc:/icons/Icons/full.png"
                
                                MouseArea {
                                    anchors.fill: parent
                
                                    onClicked: {
                                        if(startWindow.visibility == 5) startWindow.showMaximized()
                                        else startWindow.showFullScreen()
                                    }
                                }
                            }
                
                            Image {
                                source: "qrc:/icons/Icons/close.png"
                                MouseArea {
                                    anchors.fill: parent
                
                                    onClicked: Qt.quit()
                                }
                            }
                
                        }
                    }
                
                    Rectangle {
                        id: menuBar
                        anchors.top: frame.bottom
                        width: parent.width
                        height: 52
                        color: "#ffffff"
                
                        RowLayout {
                            spacing: 28
                
                            Image {
                                id: logo
                                source: "qrc:/icons/Icons/full.png"
                                Layout.preferredHeight: parent.height
                                Layout.preferredWidth: 40
                
                                MouseArea {
                                    anchors.fill: parent
                                    hoverEnabled: true
                
                                    cursorShape: Qt.PointingHandCursor
                
                                    onClicked: {
                                        howItWorksPage.visible = false
                                        defaultPage.visible = true
                                        pageInfoButton.selected = false
                                        loginButton.selected = false
                                        singUpButton.selected = false
                                    }
                                }
                            }
                
                            NaviButton {
                                id: pageInfoButton
                                text: "How it works"
                                Layout.minimumHeight:52
                                Layout.preferredHeight: 52
                                Layout.maximumHeight: 52
                
                                onStateChanged: {
                                    if(pageInfoButton.selected == true) {
                                        defaultPage.visible = false
                                        howItWorksPage.visible = true
                                        loginButton.selected = false
                                        singUpButton.selected = false
                                    }
                                }
                            }
                
                            NaviButton {
                                id: loginButton
                                text: "LOG IN"
                
                                onStateChanged: {
                                    if(loginButton.selected == true) {
                                        pageInfoButton.selected = false
                                        loginButton.selected = false
                                        singUpButton.selected = false
                
                                        var component = Qt.createComponent("qrc:/qml/LoginWindow.qml")
                                        loginWindow = component.createObject(startWindow)
                                        loginWindow.show()
                                    }
                                }
                            }
                
                            NaviButton {
                                id: singUpButton
                                text: "SIGN UP"
                
                                onStateChanged: {
                                    if(singUpButton.selected == true) {
                                        pageInfoButton.selected = false
                                        loginButton.selected = false
                                        singUpButton.selected = false
                
                //                        var component = Qt.createComponent("qrc:/qml/SignUpWindow.qml")
                //                        signUpWindow = component.createObject(startWindow)
                //                        signUpWindow.show()
                
                                          var component = Qt.createComponent("qrc:/qml/SetupMentorAccountWindow.qml")
                                          signUpWindow = component.createObject(startWindow)
                                          signUpWindow.show()
                                    }
                                }
                            }
                        }
                    }
                
                    InfoSheet {
                        id: defaultPage
                        width: parent.width
                        anchors.top: menuBar.bottom
                        anchors.left: parent.left
                        visible: false
                        headingText1: "Default"
                        headingText2: "Powerful & Connected Devices"
                        text: "We believe modern embedded development must include a cross-platform user<br>"+
                              "experience and that your tech strategy should be based on easy creation of<br>"+
                              "connected devices and UIs that run anywhere on any embedded platform including<br>"+
                              "RTOS – making your and your end users’ life easier. With Qt, you can do this and<br>"+
                              "more."
                        button1: true
                        button2: true
                    }
                
                    InfoSheet {
                        id: howItWorksPage
                        width: parent.width
                        anchors.top: menuBar.bottom
                        anchors.left: parent.left
                        visible: false
                        headingText1: "Easily Create "
                        headingText2: "Powerful & Connected Devices"
                        text: "We believe modern embedded development must include a cross-platform user<br>"+
                              "experience and that your tech strategy should be based on easy creation of<br>"+
                              "connected devices and UIs that run anywhere on any embedded platform including<br>"+
                              "RTOS – making your and your end users’ life easier. With Qt, you can do this and<br>"+
                              "more."
                    }
                }
                
                
                
                
                
                
                **Login Window**
                

                import QtQuick 2.12
                import QtQuick.Window 2.12
                import QtQuick.Controls 2.5
                import QtQuick.Controls.Styles 1.4
                import QtQuick.Controls.Material 2.12
                import QtQuick.Layouts 1.3

                ApplicationWindow {
                id: loginWindow
                visible: true
                width: 450
                height: 550

                signal openSignUpWindow()
                
                Material.theme: Material.Light
                
                flags: Qt.FramelessWindowHint
                
                property int previousX
                property int previousY
                
                property var username
                
                
                Item {
                    focus: true
                    Keys.onPressed: {
                        if (event.key === Qt.Key_Escape) {loginWindow.close();}
                    }
                }
                
                
                MouseArea {
                    anchors.fill: parent
                
                    onPressed: {
                        previousX = mouseX
                        previousY = mouseY
                    }
                
                    onMouseXChanged: {
                        var dx = mouseX - previousX
                        loginWindow.setX(loginWindow.x + dx)
                    }
                
                    onMouseYChanged: {
                        var dy = mouseY - previousY
                        loginWindow.setY(loginWindow.y + dy)
                    }
                }
                
                Rectangle {
                    id: frame
                
                    height: 24
                    width: loginWindow.width
                
                    RowLayout {
                        anchors.top: parent.top
                        anchors.right: parent.right
                        anchors.rightMargin: 8
                
                        Image {
                            source: "qrc:/icons/Icons/minimize.png"
                
                            MouseArea {
                                anchors.fill: parent
                                onClicked: loginWindow.showMinimized()
                            }
                        }
                
                        Image {
                            source: "qrc:/icons/Icons/close.png"
                            MouseArea {
                                anchors.fill: parent
                                onClicked: loginWindow.close()
                            }
                        }
                    }
                }
                
                Image {
                    id: backArrow
                    anchors.top: frame.bottom
                    visible: false
                    source: "qrc:/icons/Icons/backArrow.png"
                
                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            if(stack.depth == 2) {
                                backArrow.visible = false
                                welcomeBackLabel.text = qsTr("Welcome Back")
                            } else if(stack.depth == 3) welcomeBackLabel.text = qsTr("Reset your password.")
                              else if(stack.depth == 4) welcomeBackLabel.text = qsTr("Answer the questions.")
                             stack.pop()
                        }
                    }
                }
                
                Image {
                    id: logo
                    width: 100
                    height: 100
                    anchors.top: backArrow.bottom
                    source: "qrc:/icons/Icons/qt.jpg"
                }
                
                Label {
                    id: welcomeBackLabel
                    anchors.top: logo.bottom
                    text: qsTr("Welcome Back")
                }
                
                Label {
                    id: incorrectDataText
                    anchors.top: welcomeBackLabel.bottom
                    visible: false
                    text: qsTr("Incorrect username or password provided.")
                }
                
                StackView {
                    id: stack
                    anchors.top: incorrectDataText.bottom
                    width: parent.width
                    height: parent.height
                    initialItem: loginView
                
                    Component {
                        id: loginView
                        Rectangle {
                
                            Connections {
                                target: storage
                
                                onStatusSignal: {
                                    if(!ok) incorrectDataText.visible = true
                                }
                            }
                
                            Column {
                                spacing: 4
                
                                TextField {
                                    id: usernameTextField
                                    placeholderText: qsTr("Email or Username")
                                }
                
                                TextField {
                                    id: passwordTextFiled
                                    placeholderText: qsTr("Password")
                                }
                
                                Row {
                                    NaviButton {
                                        id: signUpLabel
                                        text: qsTr("Sign up?")
                
                                        onStateChanged: {
                                            if(signUpLabel.selected == true) {
                                                forgotPassLabel.selected = false;
                                                signUpLabel.selected = false;
                                                openSignUpWindow()
                                            }
                                        }
                                    }
                
                                    NaviButton {
                                        id: forgotPassLabel
                                        text: qsTr("Forgot Password?")
                
                                        onStateChanged: {
                                            if(forgotPassLabel.selected == true) {
                                                signUpLabel.selected = false;
                                                forgotPassLabel.selected = false;
                                                backArrow.visible = true
                                                incorrectDataText.text = qsTr("Error: The email you entered seems to be unregistered at CHOKI.")
                                                incorrectDataText.visible = false
                                                welcomeBackLabel.text = qsTr("Reset your password")
                                                stack.push(emailView)
                                            }
                                        }
                
                                    }
                                }
                
                                Button {
                                    id: loginButton
                                    text: qsTr("Log In")
                
                                    MouseArea {
                                        anchors.fill: parent
                                        hoverEnabled: true
                                        cursorShape: Qt.PointingHandCursor
                
                                        onClicked: storage.loginSlot({"username": usernameTextField.text, "password": passwordTextFiled.text})
                                    }
                                }
                            }
                        }
                    }
                
                    Component {
                        id: emailView
                        Rectangle {
                
                            Connections {
                                target: storage
                
                                onStatusSignal: {
                                    if(!ok) incorrectDataText.visible = true
                                    else {
                                        username = emailTextField.text
                                        welcomeBackLabel.text = qsTr("Answer the quetions.")
                                        incorrectDataText.visible = false
                                        stack.push(secretQuestionView)
                                    }
                                }
                            }
                
                            Column {
                                TextField {
                                    id: emailTextField
                                    validator: RegExpValidator { regExp:/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/ }
                                    placeholderText: qsTr("Enter Your email address.")
                                }
                
                                Button {
                                    id: nextButtonEV
                                    text: qsTr("Next")
                
                                    MouseArea {
                                        anchors.fill: parent
                                        hoverEnabled: true
                                        cursorShape: Qt.PointingHandCursor
                
                                        onClicked: storage.usernameSlot(emailTextField.text)
                                    }
                                }
                            }
                        }
                    }
                
                    Component {
                        id: secretQuestionView
                
                        Rectangle {
                
                            Connections {
                                target: storage
                
                                onStatusSignal: {
                                    if(!ok) {
                                        welcomeBackLabel.text = qsTr("Answer the quetions.")
                                        incorrectDataText.visible = false
                                        stack.push(secretQuestionView)
                                    }
                                    else loginWindow.close()
                                }
                            }
                
                            Column {
                                ComboBox {
                                    id: questionBox
                                    model: ["Pet", "wekl fnwefnklwef", "ewfnwefnlwlefnwek"]
                                }
                
                                Button {
                                    id: nextButtonQV
                                    text: qsTr("Next")
                
                                    MouseArea {
                                        anchors.fill: parent
                                        hoverEnabled: true
                                        cursorShape: Qt.PointingHandCursor
                
                                        onClicked: {
                                            welcomeBackLabel.text = "Enter a new password"
                                            stack.push(resetPassView)
                                        }
                                    }
                                }
                            }
                        }
                    }
                
                    Component {
                        id: resetPassView
                
                        Rectangle {
                            Connections {
                                target: storage
                
                            }
                
                            Column {
                                TextField {
                                    id: newPass
                                    placeholderText: qsTr("New password")
                                }
                
                                TextField {
                                    id: confirmNewPass
                                    placeholderText: qsTr("Confirm new password")
                                }
                
                                Button {
                                    id: changePass
                                    text: qsTr("Change Password")
                
                                    MouseArea {
                                        anchors.fill: parent
                                        hoverEnabled: true
                                        cursorShape: Qt.PointingHandCursor
                
                                        onClicked: storage.passwordSlot({"username": username, "password": confirmNewPass.text})
                                    }
                                }
                            }
                
                        }
                    }
                }
                

                }

                1 Reply Last reply
                0
                • Shrinidhi UpadhyayaS Offline
                  Shrinidhi UpadhyayaS Offline
                  Shrinidhi Upadhyaya
                  wrote on last edited by
                  #8

                  Hi @Subuday , you need to give the "modality" in the login window,i.e, remove it from "startWindow" and give it in "loginWindow".

                  Shrinidhi Upadhyaya.
                  Upvote the answer(s) that helped you to solve the issue.

                  S 1 Reply Last reply
                  2
                  • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

                    Hi @Subuday , you need to give the "modality" in the login window,i.e, remove it from "startWindow" and give it in "loginWindow".

                    S Offline
                    S Offline
                    Subuday
                    wrote on last edited by
                    #9

                    @Shrinidhi-Upadhyaya Thank you very much!

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved