The question concerns QTextEdit, not QLineEdit.

I would solve this problem by embedding the QTextEdit into a QWidget parent. Put a QVBoxLayout into the QWidget, then add a QHBoxLayout inside that. Add a QToolButton to the horizontal layout, and use a Horizontal spacer to push it to the right. Add your QTextEdit under the QHBoxLayout as the second item in the QVBoxLaout. See the screenshot below.

Capture.jpg