【发布时间】:2017-12-27 01:27:00
【问题描述】:
我正在尝试使用 Qt Quick Controls 2 为 Windows 桌面应用程序构建登录表单。我希望登录页面显示成功或失败消息。在用户按下Ok 成功后,登录表单应从视图中隐藏,并应显示另一个SettingsForm。登录失败时,用户按下Ok 后应再次显示登录表单 登录表单和设置表单都有各自的qml 和ui.qml 文件。
我无法实现登录成功时切换到 SettingsForm 的功能。这是我到目前为止所得到的:
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
import QtQuick.Window 2.3
ApplicationWindow {
visible: true
width: 900
height: 600
title: qsTr("Welcome!")
maximumHeight: height
maximumWidth: width
minimumHeight: height
minimumWidth: width
x: Screen.width / 2 - width / 2
y: Screen.height / 2 - height / 2
SwipeView {
id: swipeView
anchors.fill: parent
Page1Form {
login.onClicked: {
if (username.text == "a" && password.text == "a") {
message.title = "Login success!"
message.visible = true
}
else {
message.title = "Login Failed! Try Again."
message.visible = true
}
}
}
}
消息对话框代码:
Dialog
{
id: message
width: 300
height: 100
x:-10
standardButtons: Dialog.Ok
modal: true
onAccepted: visible=false
}
我尝试插入:
SettingsForm {
}
在message.title = "Login success!" 之后,但它不起作用。
编辑:
登录成功后的对话框如下所示:
【问题讨论】:
-
你在哪里实例化你的
Dialog?Dialog是什么类型的?来自QtQuick.Dialogs或来自QtQuick.Controls 2.x的那个? -
在 Page1Form.ui.qml 文件中实例化。它来自 QtQuick.Controls
-
在问题中添加了消息对话框的图像
标签: qt qml qtquickcontrols2