Home > OS >  How to remove spacing above the first line of a QPlainTextEdit?
How to remove spacing above the first line of a QPlainTextEdit?

Time:02-06

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?

CodePudding user response:

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.

  •  Tags:  
  • Related