move QTextCursor

  • Hi, everyone.
    I'm trying to move a QTextCursor in a specific position. I'm trying with the following code, but i'm not obtaining results:

        QTextCursor curs=ui->textEdit->textCursor();

    With this solution, the cursor simply disappears from my textEdit.
    Can you help me?

  • Lifetime Qt Champion


    What version of Qt ?
    On what OS ?
    Please provide a minimal compilable example that reproduce this behaviour.

  • Lifetime Qt Champion

    QDebug is your friend :)

       QTextCursor curs = ui->textEdit->textCursor();
        qDebug() << "now:" << curs.position();
        qDebug() << "after:" << curs.position();

    It goes to position 0

    The cursor is not vanishing by an error. ( i'm guessing here..)
    I think you use a button or something like that to test the code.
    Then the button will then take focus (when you click it) and hence the cursor is not shown since
    the TextEdit no longer has focus. the button has.

    set button to NoFocus and see.
    alt text

    alt text

  • @mrjj Thanks so much

  • Lifetime Qt Champion

    Well it also fooled me for a moment :)
    Then i recalled that buttons takes focus too so they can activate with keyboard.

Log in to reply