Wagmare
Wagmare

Reputation: 1406

setPlainText calling focusOutEvent in QGraphicsSimpleTextItem

Im overridding the focusOutEvent in QGraphicsTextItem

void EditTextItem::focusOutEvent(QFocusEvent *event)
{
    setTextInteractionFlags(Qt::NoTextInteraction);
    emit lostFocus(this);
    QGraphicsTextItem::focusOutEvent(event);
}

when the user edit the text item im saving the edited text to a file. before user edits the text im calling to show the previous text setPlainText("Old Data") which in turn calling focusOutEvent() of GraphicsTextItem and lostFocus() signal has been emitted and im saving the old data only to the file.

i want to know how to avoid setPlainText to call focusOutEvent .

Upvotes: 0

Views: 147

Answers (1)

Bowdzone
Bowdzone

Reputation: 3854

I don't know if you can avoid it but you can introduce a bool-member which is set to false before you call the setPlainText and true afterwards. In your focusOutEvent you then check the state of the member.

I usually don't like these things that much and consider them somewhat a dirty solution but often it is just an easy, fast and reliable way.

Upvotes: 1

Related Questions