In my code I create a QGraphicsTextItem which has the editing flag on.

I want to find a way to make it focused in a way that it shows the caret and allows the user to type — just like when the user clicks on it but from code.

Is there any way to perform this programmatically?

The closest I found is textItem->grabKeyboad(), which allows the user to write but does not show the dashed border and the caret is not shown until a key is pressed (no visual clue).

有帮助吗?

解决方案

There is no clue in the documentation, but this appears to work:

textItem->setFocus();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top