qt 빠른 응용 프로그램에서 작업 중이므로 대화 상자를 열고 싶습니다. 이 대화 상자 창에서 TextField가 있는데 대화 상자가 열린 후에이 텍스트로 포커스를 설정하고 싶습니다. 이 코드는 작동하지 않습니다. 콘솔에QML 대화 상자에 집중된 textField가 있습니다.
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