Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-113568

QTextDocument: calling setTextWidth(-1) breaks RTL text alignment

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.2, 6.2.4, 6.3.2, 6.4.3, 6.5.0, dev
    • GUI: Text handling
    • None
    • All

    Description

      QTextDocument: calling setTextWidth(-1) breaks RTL text alignment.

      This is old Qt bug, that is here for a decade at least (I believe since Qt 4) and
      we still have to work around in high-level code, for instance in QQuickTextEdit
      (see QQuickTextEdit::updateSize())

      The test snippet looks like this:

          QTextDocument doc;
          doc.documentLayout(); // create default doc layout
          doc.setPlainText("טֶקסט\nשדגשגשגשגדוגמא\nטֶקסט");
          doc.setTextWidth(-1);
      
          QRectF firstLineRect;
          for (auto block = doc.begin(); block != doc.end(); block = block.next()) {
              auto *blockLayout = block.layout();
              for (int i = 0; i < blockLayout->lineCount(); ++i) {
                  const auto textLine = blockLayout->lineAt(i);
                  if (firstLineRect.isNull()) {
                      firstLineRect = textLine.rect();
                  } else {
                      Q_ASSERT(qFuzzyCompare(textLine.rect().right(), firstLineRect.right()));
                  }
              }
          }
      

      See full example TextDocBug.zip

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              esabraha Eskil Abrahamsen Blomfeldt
              studiosus Vladimir Belyavsky
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes