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

positionAt() function gives the wrong result if the line ends with an image and this line is wrapped by wrapMode

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.12.5, 5.13.1, 5.14.0 Beta 1
    • None
    • Linux/X11, macOS, Windows

    Description

      This function gives wrong result if line ends with an image and this line is wrapped by wrapMode.
       https://doc.qt.io/qt-5/qml-qtquick-textedit.html#positionAt-method

      Steps to reproduce:
      1. Create TextEdit component with rich text format.
      2. Add text with an image at the end of the line, for example - "This line breaks by warp and ends with an image <img src='qrc:/images/arrow.png'>This line breaks by warp"
      3. Set TextEdit width to be equal with line break after the image
      4. Then the function positionAt will give an incorrect result, if X coord is outside of the line.
       
      For example, if the text is 10 characters long plus 1 char is an image, total length will be 11. If there is no line break, then function gives the correct result 11, even if the x coordinate is out of line. It also works if the line breaks with line break character <br>.
      But the problem occures when line breaks with wrap mechanism and positionAt will return 10 if the X coordinate is outside the line, but total length is 11.
       
      I attach video and qml code, modified TextFieldPage.qml file from Gallery example.
      Log:
      qml: Mouse click coord 252.8 37.0 char pos 42
      qml: Mouse click coord 259.1 37.7 char pos 43
      qml: Mouse click coord 267.7 38.5 char pos 44
      qml: Mouse click coord 286.5 38.7 char pos 45
      qml: Mouse click coord 296.4 39.0 char pos 46
      qml: Mouse click coord 306.8 38.2 char pos 46
      qml: Mouse click coord 321.6 39.5 char pos 45
      qml: Mouse click coord 326.4 39.8 char pos 45
      qml: Mouse click coord 329.9 40.0 char pos 45
      qml: Mouse click coord 334.8 40.0 char pos 45
       
      You can see, that the X coordinate is increasing, like the result of the function, but when X exceeds the width, it gives an incorrect result, 45 instead of 46.

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            freed Igor Bugaev
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes