You do not need a function because it is written. From the Dialog docs for the open() function:
Shows a dialog to the user. This is equivalent to setting the visible to true.
Given that (this is not a problem), it seems that the focus is constantly being discussed between the dialogue and the contained element. The more you open / close Dialog , the more evaluations occur. I canโt understand why this is happening now. However, you can easily solve the problem: (1) get rid of the onVisibilityChanged handler and (2) rewrite newFolder() . The final code is rewritten:
ApplicationWindow { width: 360 height: 300 visible: true Button { anchors.centerIn: parent text: "click me!" onClicked: newFolder() } Dialog { id: newFolderDialog title: "New folder" height: 150 width: 300 standardButtons: StandardButton.Ok | StandardButton.Cancel focus: true // Needed in 5.9+ or this code is NOT going to work!! 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) } } } function newFolder() { newFolderDialog.open() newFolderInput.focus = true } }
Thus, you first open the dialog box, and then set the focus to the correct Item .
source share