see code changesHi, 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
Qt Code:
{ if ( !uiL->textEdit->find(text, flags) ) { // if searching backward move cursor at the end QTextCursor mycursor; uiL->textEdit->setTextCursor(mycursor); } // if searching foreward move cursor at the start QTextCursor mycursor; uiL->textEdit->setTextCursor(mycursor); } // 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; mycursor.movePosition(QTextCursor::End); // try here instead uiL->textEdit->setTextCursor(mycursor); } // if searching foreward move cursor at the start if ( flags != QTextDocument::FindBackward ) { QTextCursor mycursor; uiL->textEdit->setTextCursor(mycursor); mycursor.movePosition(QTextCursor::Start); // THIS WORKS - actually, this doesnt do anything... } // 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
do you know the reason why your way cannot work?
Bookmarks