3

I'm using C++ and Qt on Windows to create a simple application which outputs some data to the screen using a QPlainTextEdit.

The problem is that there is a small internal margin between the QPlainTextEdit's border and the text as shown here:

The text in the QPlainTextEdit has been selected to highlight the gap.

I have tried using setContentsMargins(0, 0, 0, 0) and setStyleSheet("padding:0;"), and using a QTextEdit or a QTextBrowser instead, but I still get that small margin.

Googling it only turned up this unanswered question on qtcentre.org.

YmFzZTY0
  • 109
  • 1
  • 9
  • 1
    Qt controls vary in looks to mimic the look and feel of native platform widgets so you may want to dig into the implementation details of whatever platform(s) you target. – dtech Oct 18 '14 at 17:14

1 Answers1

10

Use QTextDocument::setDocumentMargin(). Setting it to zero does the trick. To obtain QTextDocument there's a method QPlainTextEdit::document().

Oleg Shparber
  • 2,732
  • 1
  • 18
  • 19