Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Use QTextCursor to get end of line...

Use QTextCursor to get end of line...

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Peppy
    wrote on last edited by
    #1

    Hi guys, I have one simple question for you: How to use QTextCursor, to get EOL from the current position of the text cursor?

    Or other way: how to get lenght of current line in QTextEdit ?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DerManu
      wrote on last edited by
      #2

      Consider
      @ textCursor.block().length() @

      But note that in text documents it isn't so easy speaking of "current lines", because there are block endings (static paragraph newlines) aswell as newlines induced by the layout wrapping of a block (dynamic newlines). The latter may change whenever other parameters of the document are changed, i.e. the document width, or any elements before that newline.
      If you are searching for the position of dynamic newlines due to wrapping, you will find a solution by looking at the layout, i.e. textCursor.block().layout() with its functions lineAt() or lineForTextPosition() which will help you. For example by getting the respective QTextLine and handling that further with its textLength function which returns what you want.
      The second way is creating a second text cursor, moving it to the line end (move operation QTextCursor::EndOfLine), and getting its position. Then moving it to the start of the line and subtracting that position from the previous one. But that's a bit hackish in my opinion.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Peppy
        wrote on last edited by
        #3

        Thanks man, I will look at it.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved