Qt World Summit: Register Today!

How to find current line number in QTextEdit?

  • I need to get a position of a text cursor in QTextEdit counted in number of lines.
    In the docs I can only see textCursor().position() function which counts it in characters.

    I also found the QTextLayout class, with has lineForTextPosition() function, but i am not sure if it is what I am looking for, as according to help it serves purpose of putting text into widgets of various shapes and looks like huge overkill to my purposes.

  • Lifetime Qt Champion


    The solution proposed here might be what you are looking for.

Log in to reply