[英]How do I remove the space between QPlainTextEdit and its contents
I'm using C++ and Qt on Windows to create a simple application which outputs some data to the screen using a QPlainTextEdit. 我在Windows上使用C ++和Qt创建一个简单的应用程序,该应用程序使用QPlainTextEdit将一些数据输出到屏幕上。 The problem is that there is a small internal margin between the QPlainTextEdit's border and the text as shown here: http://i.stack.imgur.com/ovIrJ.png . 问题在于QPlainTextEdit的边框和文本之间的内部空白很小,如下所示: http ://i.stack.imgur.com/ovIrJ.png。
(The text in the QPlainTextEdit has been selected to highlight the gap) (已选择QPlainTextEdit中的文本以突出显示空白)
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. 我尝试使用setContentsMargins(0, 0, 0, 0)
和setStyleSheet("padding:0;")
,并使用QTextEdit或QTextBrowser代替,但是我仍然得到了很小的利润。
Googling it only turned up this unanswered question on qtcentre.org . 谷歌搜索只会在qtcentre.org上出现这个未解决的问题 。
I know this is kind of a trivial thing but its really been annoying me for a while now. 我知道这是一件微不足道的事情,但现在确实让我很烦。
Thanks in advance for any help! 在此先感谢您的帮助!
Use QTextDocument::setDocumentMargin() . 使用QTextDocument :: setDocumentMargin() 。 Setting it to zero does the trick. 将其设置为零就可以了。 To obtain QTextDocument there's a method QPlainTextEdit::document() . 要获得QTextDocument,有一个方法QPlainTextEdit :: document() 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.