我将其归咎于我的疲倦,但我正在努力寻找如何通过按钮将用户引导到新选项卡:
我有一个登录页面,如果用户输入了正确的用户名和密码,按下登录按钮将会引导用户进入一个新选项卡。
TextField { id: inputTo placeholderText: "Username:" } TextField { id: inputFrom placeholderText: "password" echoMode: TextInput.Password } Button { objectName: "button" width: parent.width text: "Login" onClicked: { if(inputTo.text == "----" & inputFrom.text == "---" ){ label.text = "Succesful" } else label.text = "Wrong Username or Password" } }
有人能告诉我如何让按钮引导用户进入新标签吗?谢谢 :)
答案1
我更改了 Ubuntu-SDK 选项卡模板以启用密码检查。我对 qml 也完全陌生,但也许这就是你想要的:
项目->新建->ubuntu->Ubuntu-UI-Tabs 作为 tabstest:这是我的 tabstest.qml
import QtQuick 2.0
import Ubuntu.Components 0.1
/*
example : check password before changing/showing tab
*/
MainView {
// objectName for functional testing purposes (autopilot-qt5)
objectName: "mainView"
applicationName: "tabstest"
width: units.gu(100)
height: units.gu(75)
Tabs {
id: tabs
anchors.fill: parent
// First tab begins here
Tab {
objectName: "Tab1"
title: i18n.tr("Password-Entry-tab")
// Tab content begins here
page: Page {
Column {
anchors.centerIn: parent
Label {
text: i18n.tr("this is the password check tab")
}
}
}
Column {
id: pageLayout
Label{
id : labelX
text : "Enter your paasword:"
}
TextField {
id: inputFrom
placeholderText: "password"
echoMode: TextInput.Password
}
Button {
objectName: "button"
width: parent.width
text: "Login"
onClicked: {
console.debug("onclicked...");
if(inputFrom.text == "test" ){
labelX.text = "Succesful"
console.debug(tabs.selectedTab );
tabs.visible = false
tabs2.visible = true
} else {
labelX.text = "Wrong Username or Password"
}
}
}
}
}
}
Tabs {
id: tabs2
visible: false
// Second tab begins here
Tab {
objectName: "Tab2"
title: i18n.tr("..secured tab")
page: Page {
anchors.margins: units.gu(2)
tools: ToolbarActions {
Action {
objectName: "action"
iconSource: Qt.resolvedUrl("avatar.png")
text: i18n.tr("Tap me!")
onTriggered: {
label.text = i18n.tr("Toolbar tapped")
}
}
}
Column {
anchors.centerIn: parent
Label {
id: label
objectName: "label"
text: i18n.tr("you are in secured tab.")
}
}
}
} anchors.fill: parent
}
}
问候 Sascha