QLabel: lay out text using a text control when label can get focus

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 <jan-arve.saether@qt.io>
bb10
Volker Hilsheimer 2020-05-11 12:29:40 +02:00
parent d26ee69140
commit 7bee4e9cb3
1 changed files with 3 additions and 1 deletions

View File

@ -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;