为了详细阐述我遇到的
问题,我制作了一个小程序。
我在运行程序的时候,发现Tab页内的第一个控件在Tab点击了的之后得到了focus,事实上我是不希望获得focus的,这个问题该如何处理呢?
程序代码:
import QtQuick 2.3
import QtQuick.Controls 1.2
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("First control focus problem")
menuBar: MenuBar {
Menu {
title: qsTr("File")
MenuItem {
text: qsTr("&Open")
onTriggered: console.log("Open action triggered");
}
MenuItem {
text: qsTr("Exit")
onTriggered: Qt.quit();
}
}
}
TabView
{
id: tabView
anchors.fill: parent
Tab
{
title: qsTr( "first tab" )
Rectangle
{
TextField
{
id: textField
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: defaultText.top
text: qsTr( "textField_1" )
}
Text
{
id: defaultText
text: qsTr( "It is
not expected to be visible." )
visible: textField.focus
color: "red"
anchors.centerIn: parent
}
Button
{
anchors.top: defaultText.bottom
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr( "Test button" )
}
}
}
Tab
{
title: qsTr( "first tab" )
Rectangle
{
TextField
{
id: textField_2
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: defaultText_2.top
text: qsTr( "textField_2" )
}
Text
{
id: defaultText_2
text: qsTr( "It is not expected to be visible." )
visible: textField_2.focus
color: "red"
anchors.centerIn: parent
}
Button
{
anchors.top: defaultText_2.bottom
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr( "Test button" )
}
}
}
}
}
程序截图:
问题工程代码 FirstControlFocus.7z (2 K) 下载次数:0 红色的字不应该出现的。这是因为textField_2获得了focus。怎样才能让其不获取到focus呢?