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(); curs.movePosition(QTextCursor::Start); ui->textEdit->setTextCursor(curs);
With this solution, the cursor simply disappears from my textEdit.
Can you help me? -
Hi,
What version of Qt ?
On what OS ?
Please provide a minimal compilable example that reproduce this behaviour. -
Hi
QDebug is your friend :)QTextCursor curs = ui->textEdit->textCursor(); qDebug() << "now:" << curs.position(); curs.movePosition(QTextCursor::Start); ui->textEdit->setTextCursor(curs); 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.
-
Hi
QDebug is your friend :)QTextCursor curs = ui->textEdit->textCursor(); qDebug() << "now:" << curs.position(); curs.movePosition(QTextCursor::Start); ui->textEdit->setTextCursor(curs); 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.
@mrjj Thanks so much
-
@mrjj Thanks so much
@Martinuccia_96
Well it also fooled me for a moment :)
Then i recalled that buttons takes focus too so they can activate with keyboard.