From cbb94c29b065222e7cd8a5b55b018f14d3b79984 Mon Sep 17 00:00:00 2001 From: mae Date: Fri, 2 Oct 2009 12:30:58 +0200 Subject: Clear text selection in QLabel when it is losing focus The change implements the same logic for QLabel which QLineEdit (and implicitely QSpinBox and QComboBox) already had. Reviewed-by: Simon Hausmann --- src/gui/widgets/qlabel.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/qlabel.cpp b/src/gui/widgets/qlabel.cpp index 5ff323a..5ba0571 100644 --- a/src/gui/widgets/qlabel.cpp +++ b/src/gui/widgets/qlabel.cpp @@ -886,7 +886,18 @@ void QLabel::focusInEvent(QFocusEvent *ev) void QLabel::focusOutEvent(QFocusEvent *ev) { Q_D(QLabel); - d->sendControlEvent(ev); + if (d->control) { + d->sendControlEvent(ev); + QTextCursor cursor = d->control->textCursor(); + Qt::FocusReason reason = ev->reason(); + if (reason != Qt::ActiveWindowFocusReason + && reason != Qt::PopupFocusReason + && cursor.hasSelection()) { + cursor.clearSelection(); + d->control->setTextCursor(cursor); + } + } + QFrame::focusOutEvent(ev); } -- cgit v0.12