Important: Please read the Qt Code of Conduct -

Replace text from where user left the cursor

  • Hi,

    I developed a Find/Replace feature for my editor. In case of replaceText(), the text is being replaced from the start of the document. Ideally, it should start replacing from where the user left the cursor position. Please help me regarding this.

    My code:
    void MyEditor::replaceText(const QString &findWord, const QString &replaceWord)
    if(textEdit->find(findWord, QTextDocument::FindCaseSensitively))
    I need to start replacing text not from START of doc, but from where user had left the cursor.


    [edit] code wrappings added, koahnig

  • Please use "code wrappings": when posting code sections

  • You could work with the find() methods of the [[Doc:QTextDocument]] attached to the QTextEdit. Those methods take a [[Doc:QTextCursor]] or int argument as the starting point of the search.

Log in to reply