i have an action called bold, when i select text then run this action this code will run:

Qt Code:
  1. void MarkEditWindow::on_actionBold_triggered()
  2. {
  3. QTextCursor selectionBegin(ui->markdownEdit->document());
  4. selectionBegin.setPosition(ui->markdownEdit->textCursor().anchor());
  5. selectionBegin.insertText("**");
  6.  
  7. QTextCursor selectionEnd(ui->markdownEdit->document());
  8. selectionEnd.setPosition(ui->markdownEdit->textCursor().position());
  9. selectionEnd.insertText("**");
  10. }
To copy to clipboard, switch view to plain text mode 


now for example i wrote “test” then run the action the result is “test” and the selected text will be “test**” (missing first ‘**’)
how can i move the cursor after selection to make it select “test” or even select “test” only
i tried a lot of things and didn’t work, like:

Qt Code:
  1. selectionEnd.movePosition(QTextCursor::Left);
  2. selectionEnd.movePosition(QTextCursor::Left);
To copy to clipboard, switch view to plain text mode 

but didn’t work! :-(