Use QTextCursor to get end of line...
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 ?
@ 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.
Thanks man, I will look at it.