It does exactly what you are asking for. QLineEdit::paste()
Inserts the clipboard's text at the cursor position, deleting any selected text, providing the line edit is not read-only.
If all the text in the line edit is selected then paste() replaces all the text. If no text in the line edit is selected then paste() inserts the text. See also
QLineEdit::deselect(), QLineEdit::selectAll(), QLineEdit::setCursorPosition() etc.