Hi, I am using QTextCursor to move my cursor at the Start and at the End of my QTextEdit document.
Strangely, while I can move it to the Start with QTextCursor::Start, it seems it does not move to the end with QTextCursor::End
Here is my code
{
if ( !uiL->textEdit->find(text, flags) ) {
// if searching backward move cursor at the end
uiL->textEdit->setTextCursor(mycursor);
mycursor.
movePosition(QTextCursor::End);
// THIS DOES NOT WORK, OR AT LEAST IT SEEMS SO }
// if searching foreward move cursor at the start
uiL->textEdit->setTextCursor(mycursor);
mycursor.
movePosition(QTextCursor::Start);
// THIS WORKS }
// once cursor is moved search again. If return false than the word does not exist in the doc
if ( !uiL->textEdit->find(text, flags) ) {
qDebug()<<"Not found";
}
}
}
void MyPage::find(const QString &text, QTextDocument::FindFlags flags)
{
if ( !uiL->textEdit->find(text, flags) ) {
// if searching backward move cursor at the end
if ( flags == QTextDocument::FindBackward ) {
QTextCursor mycursor;
uiL->textEdit->setTextCursor(mycursor);
mycursor.movePosition(QTextCursor::End); // THIS DOES NOT WORK, OR AT LEAST IT SEEMS SO
}
// if searching foreward move cursor at the start
if ( flags != QTextDocument::FindBackward ) {
QTextCursor mycursor;
uiL->textEdit->setTextCursor(mycursor);
mycursor.movePosition(QTextCursor::Start); // THIS WORKS
}
// once cursor is moved search again. If return false than the word does not exist in the doc
if ( !uiL->textEdit->find(text, flags) ) {
qDebug()<<"Not found";
}
}
}
To copy to clipboard, switch view to plain text mode
So basically when I am searching backward I always get "Not Found" when reached the top, I would expect to find the first occurrence from the bottom instead. DOes it make sense?
Thanks,
Jan
Bookmarks