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

QTextEdit cursor is drawn incorrectly

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 6.0.1
    • Fix Version/s: 6.0.4, 6.1.1, 6.2.0 Alpha
    • Component/s: GUI: Text handling
    • Labels:
      None
    • Environment:
      deepin V20
    • Platform/s:
      Linux/X11
    • Commits:
      e99a883bd382ca950192bd66cafb2a1de6394ce7 (qt/qtbase/dev) 9b0ffccabd0bf668b052b0ce74980cc3a0b859e5 (qt/qtbase/6.0) bed37717886721888d87a80911a3403df9ef46c9 (qt/qtbase/6.1)

      Description

      I overloaded the QTextObjectInterface class to draw an Object. When the cursor is at the end of the Object, there is an error in the starting position of the cursor drawing, just like the GIF in the attachment.

       

      I overloaded the QTextObjectInterface class to draw an Object. When the cursor is at the end of the Object, there is an error in the starting position of the cursor drawing, just like the GIF in the attachment.

       

      Below is the code for me to insert an Object. Now there is a problem with the cursor position, just like the GIF in the attachment.

       

       

      void Widget::on_pushButton_clicked(bool checked)
      {
          QString text = "123";
          QTextCharFormat format;
          format.setObjectType(TO_ObjectAt);
          format.setProperty(OP_Text, QVariant::fromValue(text));
          format.setProperty(OP_FontSize, QVariant::fromValue(14));
          format.setVerticalAlignment(QTextCharFormat::AlignBottom);
          ui->textEdit->textCursor().insertText(QString(QChar::ObjectReplacementCharacter),
                                                format);
          qDebug() << "insert text object: " << text;
      }

       

      After analysis, when an error occurs, the Y coordinate of the cursor is -1.5. Because sl.base <base. When si.ascent> 0, base = si.ascent. So sl.base <si.ascent.

       

      si.ascent comes from QTextDocumentLayout::resizeInlineObject. When the alignment is AlignBottom, si.ascent defaults to the height of the Object.The value of si.descent is 0, we should consider this situation when calculating the starting position of the cursor

       

       

       QTBUG-92468.tar.gz is my test project, click insert to insert Object.

       

       

       

        Attachments

        1. image-2021-04-07-15-32-04-472.png
          image-2021-04-07-15-32-04-472.png
          151 kB
        2. macos-11.2-qt6.2.mov
          544 kB
        3. QTBUG-92468.gif
          QTBUG-92468.gif
          48 kB
        4. QTBUG-92468.tar.gz
          100 kB

          Issue Links

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

            Activity

              People

              Assignee:
              esabraha Eskil Abrahamsen Blomfeldt
              Reporter:
              tanghaixiang haixiang tang
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There is 1 open Gerrit change