diff options
author | Vladimir Belyavsky <belyavskyv@gmail.com> | 2023-04-14 18:29:53 +0300 |
---|---|---|
committer | Vladimir Belyavsky <belyavskyv@gmail.com> | 2023-06-02 09:57:49 +0300 |
commit | 58780ee99ac7c6f46f72143c6a801e2be8877dd2 (patch) | |
tree | 408777cd2025cabcb15425eaec76472f7489adcd /src/quick/items/qquicktextedit.cpp | |
parent | 7aa757f95da35dd81171d1b0b9621ca097d065f1 (diff) |
TextEdit: fix wrong RTL text alignment when used with a ColumnLayout
Due to some old bug in QTextDocument, invalidating document's
width (via setTextWidth(-1)) also breaks RTL text alignment.
It was a reason of broken text alignment in case when TextEdit
control is placed into a layout. To avoid this, we have to call
setTextWidth("idealWidth") all the time when an explicit width
is not set and text wrapping is not used.
As a drive-by change, we slightly polished the surrounding code
to make it a bit clear.
Fixes: QTBUG-112858
Pick-to: 6.5
Change-Id: I59cb0618d939d05fedbbabc59a8aae0e2ecabaee
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/quick/items/qquicktextedit.cpp')
-rw-r--r-- | src/quick/items/qquicktextedit.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp index ce91af040d..1ddc149f2b 100644 --- a/src/quick/items/qquicktextedit.cpp +++ b/src/quick/items/qquicktextedit.cpp @@ -2718,9 +2718,6 @@ void QQuickTextEdit::updateSize() return; } - qreal naturalWidth = d->implicitWidth - leftPadding() - rightPadding(); - - qreal newWidth = d->document->idealWidth(); // ### assumes that if the width is set, the text will fill to edges // ### (unless wrap is false, then clipping will occur) if (widthValid()) { @@ -2732,8 +2729,7 @@ void QQuickTextEdit::updateSize() } if (d->requireImplicitWidth) { d->document->setTextWidth(-1); - naturalWidth = d->document->idealWidth(); - + const qreal naturalWidth = d->document->idealWidth(); const bool wasInLayout = d->inLayout; d->inLayout = true; if (d->isImplicitResizeEnabled()) @@ -2743,19 +2739,22 @@ void QQuickTextEdit::updateSize() return; // get this far we'll get a warning to that effect. } const qreal newTextWidth = width() - leftPadding() - rightPadding(); - if (d->document->textWidth() != newTextWidth) { + if (d->document->textWidth() != newTextWidth) + d->document->setTextWidth(newTextWidth); + } else if (d->wrapMode == NoWrap) { + // normally, if explicit width is not set, we should call setTextWidth(-1) here, + // as we don't need to fit the text to any fixed width. But because of some bug + // in QTextDocument it also breaks RTL text alignment, so we use "idealWidth" instead. + const qreal newTextWidth = d->document->idealWidth(); + if (d->document->textWidth() != newTextWidth) d->document->setTextWidth(newTextWidth); - newWidth = d->document->idealWidth(); - } - //### need to confirm cost of always setting these - } else if (d->wrapMode == NoWrap && d->document->textWidth() != newWidth) { - d->document->setTextWidth(newWidth); // ### Text does not align if width is not set or the idealWidth exceeds the textWidth (QTextDoc bug) } else { d->document->setTextWidth(-1); } QFontMetricsF fm(d->font); - qreal newHeight = d->document->isEmpty() ? qCeil(fm.height()) : d->document->size().height(); + const qreal newHeight = d->document->isEmpty() ? qCeil(fm.height()) : d->document->size().height(); + const qreal newWidth = d->document->idealWidth(); if (d->isImplicitResizeEnabled()) { // ### Setting the implicitWidth triggers another updateSize(), and unless there are bindings nothing has changed. |