[SOLVED] How to remove spacing above the first line of a QPlainTextEdit?


I am working on creating a line numbers widget for a QPlainTextEdit. It is basically a QListWidget. However, I have detected a small space only above the first line of a QPlainTextEdit as you can see in my screenshot.

enter image description here

How can I remove this space and even know the exact height of it?


Try setting QTextDocument::setDocumentMargin() https://doc.qt.io/qt-5/qtextdocument.html#documentMargin-prop, which you can access by calling QPlainTextEdit::document() https://doc.qt.io/qt-5/qplaintextedit.html#document, or QPlainTextEdit::setViewportMargins() https://doc.qt.io/qt-5/qabstractscrollarea.html#setViewportMargins to 0. I am not sure which one will work in your case, but these both can be used for creating some blank space around the document, one of them will certainly work.

Answered By – V.K.

Answer Checked By – Marilyn (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *