0

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).

Alicia
  • 1,132
  • 1
  • 14
  • 28

1 Answers1

1

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

textItem->setFocus();
Pavel Strakhov
  • 39,123
  • 5
  • 88
  • 127
  • I already tried that and it did not work :\ I'm using Qt 5.1.1. Could you put some example code? – Alicia Nov 15 '13 at 09:13
  • Hmmm... I wrote a simpler code myself with just that and it worked there (in the original code that formed part of a mouse pressed handler). – Alicia Nov 15 '13 at 09:33
  • I found it. It works with that. :) It was just that I was unfocusing it calling superclass' `mousePressEvent`. – Alicia Nov 15 '13 at 10:57