From 7bee4e9cb3750be4573e1872f52023081b014500 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 11 May 2020 12:29:40 +0200 Subject: [PATCH] QLabel: lay out text using a text control when label can get focus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QLabel ensures a text control in its focusInEvent, and from that point on lays the text out using the control. A label with text control will place the text so that there is space for a cursor and text selection, resulting in text shifting when a label receives focus without having had a text control before. Instead of creating the control only on focusIn, ensure that it's created for any QLabel that can receive focus. Change-Id: I26c9df3affa08f2360ad4b94de43bd85e2e2e164 Fixes: QTBUG-84080 Pick-to: 5.15 Reviewed-by: Jan Arve Sæther --- src/widgets/widgets/qlabel_p.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/widgets/widgets/qlabel_p.h b/src/widgets/widgets/qlabel_p.h index 6b3fbc5f0c..4458df3b3e 100644 --- a/src/widgets/widgets/qlabel_p.h +++ b/src/widgets/widgets/qlabel_p.h @@ -92,9 +92,11 @@ public: void _q_buddyDeleted(); #endif inline bool needTextControl() const { + Q_Q(const QLabel); return isTextLabel && (effectiveTextFormat != Qt::PlainText - || (textInteractionFlags & (Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard))); + || (textInteractionFlags & (Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard)) + || q->focusPolicy() != Qt::NoFocus); } void ensureTextPopulated() const;