If you observe the source code, we see that the function is defined as follows:
void QTextDocument::setDocumentMargin(qreal margin)
{
// ...
QTextFrame* root = rootFrame();
QTextFrameFormat format = root->frameFormat();
format.setMargin(margin);
root->setFrameFormat(format);
// ...
}
So we can do the same through the functions rootFrame()
and frameFormat()
as I show below:
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
textEdit = QTextEdit()
format = textEdit.document().rootFrame().frameFormat()
format.setBottomMargin(10)
# format.setTopMargin(value)
# format.setLeftMargin(value)
# format.setRightMargin(value)
textEdit.document().rootFrame().setFrameFormat(format)
textEdit.show()
sys.exit(app.exec_())
If you just want to make a QTextEdit scrollbar visible, use the following:
textEdit.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
textEdit.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)