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

QTextFormat::FullWidthSelection does not work with right-to-left text layout

    XMLWordPrintable

Details

    • Linux/X11
    • a7894855f2f59028bea9cd1aef07ec1e2c713c90 (qt/qtbase/dev) 952635dabe24acf3d222acad3f959c9d33b760aa (qt/qtbase/6.1) 5f298f6e8ec1b29da4978942383b2ec54b7cd879 (qt/qtbase/6.2) e8bc2067eb2bcd40cab3515b84944408e1d56ff0 (qt/tqtc-qtbase/5.15)

    Description

      QTextFormat::FullWidthSelection is a property that you can set on a selection to make it highlight the full width of the line.

      It works fine with left-to-right languages, but does not work with right-to-left ones (like Arabic, Persian or Hebrew): only the text is highlighted, the remaining space after it is not highlighted.

      Here is a test case:

      #include <QtCore/QList>
      #include <QtGui/QTextCursor>
      #include <QtGui/QTextFormat>
      #include <QtWidgets/QApplication>
      #include <QtWidgets/QTextEdit>
      
      int main(int argc, char **argv) {
          QApplication app(argc, argv);
      
          QTextEdit edit;
          edit.setPlainText("فارسی\n\nEnglish\n");
          QList<QTextEdit::ExtraSelection> selections;
      
          for (int i = 0; i < 2; ++i) {
              QTextEdit::ExtraSelection selection;
              selection.format.setProperty(QTextFormat::FullWidthSelection, true);
              selection.format.setBackground(Qt::yellow);
              selection.cursor = edit.textCursor();
              selections.append(selection);
          }
          selections[1].cursor.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor, 2);
      
          edit.setExtraSelections(selections);
          edit.show();
      
          return app.exec();
      }
      

      It creates two selections: first one on RTL line and second on LTR. A screenshot is attached which demonstrates that only the second selection works as expected.

      When highlighting the multi-line block, all lines except the first one are highlighted in full width, but the first one is not. See the second screenshot in this comment.

      Attachments

        For Gerrit Dashboard: QTBUG-91125
        # Subject Branch Project Status CR V

        Activity

          People

            hurlevent Oliver Eftevaag
            mandriver Dmitry Shachnev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews