'PyQt5 set QTextEdit document margin (constantly)

I would like to set a permanent margin in QTextEdit. And I found out about self.document().rootFrame(). I tried to set the left and right margin, however, the placeholder text is not adapting the margin same with clearing the text using self.clear()



Solution 1:[1]

Try setting QTextDocument::setDocumentMargin() https://doc.qt.io/qt-5/qtextdocument.html#documentMargin-prop, which you can access by calling QTextEdit::document() https://doc.qt.io/qt-5/qplaintextedit.html#document, or QTextEdit::setViewportMargins() https://doc.qt.io/qt-5/qabstractscrollarea.html#setViewportMargins. I am not sure which one will work best in your case. You need to try it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 HiFile the best file manager