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

QTextEdit cursor is drawn incorrectly

    XMLWordPrintable

Details

    • Linux/X11
    • e99a883bd382ca950192bd66cafb2a1de6394ce7 (qt/qtbase/dev) 9b0ffccabd0bf668b052b0ce74980cc3a0b859e5 (qt/qtbase/6.0) bed37717886721888d87a80911a3403df9ef46c9 (qt/qtbase/6.1) b7c4b74146 (qt/tqtc-qtbase/5.15) b7c4b74146 (qt/tqtc-qtbase/tqtc/vxworks-5.15.10)

    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. QTBUG-92468.gif
          QTBUG-92468.gif
          48 kB
        2. image-2021-04-07-15-32-04-472.png
          image-2021-04-07-15-32-04-472.png
          151 kB
        3. QTBUG-92468.tar.gz
          100 kB
        4. macos-11.2-qt6.2.mov
          544 kB
        5. image-2022-10-14-10-33-31-483.png
          image-2022-10-14-10-33-31-483.png
          119 kB

        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
              tanghaixiang haixiang tang
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews