我正在开发qt快速应用程序,我想打开对话框。在这个对话窗口中是TextField,我想在对话框打开后将焦点设置到这个文本框。 此代码没有工作。带聚焦textField的QML对话框
function newFolder() {
newFolderDialog.visible = true
newFolderDialog.open()
}
Dialog {
id: newFolderDialog
title: "New folder"
height: 150
width: 300
standardButtons: StandardButton.Ok | StandardButton.Cancel
Column {
anchors.fill: parent
Text {
text: "Name"
height: 40
}
TextField {
id: newFolderInput
width: parent.width * 0.75
focus: true
onFocusChanged: console.log("Focus changed " + focus)
}
}
onVisibilityChanged: {
if(visible === true){
newFolderInput.text = ""
newFolderInput.focus = true
}
}
}
输出到控制台
QML:重点变成假
QML:重点变成真正
QML:重点变成假
它的样子,不知怎的焦点在我将焦点设置为textField后更改了
这适用于我在Qt 5.5中。重点放在TextField上,控制台中有四行(false,true,false,true)。 – pepan 2016-02-08 10:57:17