Nominate our 2022 Qt Champions!

QTextCursor::setPosition() not working in my QTextEdit.

  • Hi, I cannot manage to move textCursor of QTextEdit with setPosition function.
    The following instruction does not work in my Qt 5.10.0:


    Nothing happens. I want to move cursor to specific position in the text already written, thats why i'm not using movePosition function.


  • Lifetime Qt Champion

    You need to set the cursor with setTextCursor(). textCursor only returns the current QTextCursor. See documentation:

    "Returns a copy of the QTextCursor that represents the currently visible cursor. Note that changes on the returned cursor do not affect QTextEdit's cursor; use setTextCursor() to update the visible cursor."

  • Thanks Christian.
    So the code is like this:

     QTextCursor cursor = tbx->textCursor();

Log in to reply