Solved How to make a window inactive?
-
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.
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 } } } }
-
You can try with window modality property.
-
@dheerendra said in How to make a window inactive?:
You can try with window modality property.
Could you explain, please?
-
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 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
-
Hi @Subuday , can you share the complete code,i mean the code for the background window also.
-
@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.3ApplicationWindow {
id: loginWindow
visible: true
width: 450
height: 550signal 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}) } } } } } }
}
-
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 Thank you very much!