I have a TextItem
inheriting QGraphicsTextItem
. I made it so that on double-click I can edit the text, and when clicking out, the text is no longer editable.
void TextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event)
{
setTextInteractionFlags(Qt::TextEditorInteraction);
setFocus();
int p = document()->documentLayout()->hitTest(event->pos(), Qt::FuzzyHit);
QTextCursor _cursor = textCursor();
_cursor.setPosition(p);
setTextCursor(_cursor);
}
void TextItem::focusOutEvent(QFocusEvent *event)
{
Q_UNUSED(event);
setTextInteractionFlags(Qt::NoTextInteraction);
}
When clicking out, the text is no longer editable - but the caret is still visible.
Adding setCursor(Qt::OpenHandCursor);
in the focusOutEvent
(and possibly trying to remember which cursor shape to set... I don't know how yet) fixes this - makes the caret disappear - but I don't think it is the right fix.
Yet I cannot find any method in QTextCursor
to hide the caret when no longer in edit mode - and it seems that setting NoTextInteraction
should have done that...
What is the best way to hide the caret when not in edit mode ?