简体   繁体   English

如何删除QPlainTextEdit及其内容之间的空间

[英]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.

相关问题 如何将项目从 QListWidget 拖放到 QPlainTextEdit? - How do i drag item from QListWidget and drop to QPlainTextEdit? 如何根据其内容确定QGraphicsTextItem的boundingRect()? - How do I determine the boundingRect() of a QGraphicsTextItem based on its contents? 销毁向量时如何释放其内容? - How do I deallocate contents of a vector upon its destruction? 以编程方式编辑QPlainTextEdit的内容 - Programmatically edit the contents of a QPlainTextEdit 如何从QTextEdit或QPlainTextEdit小部件获取当前可见的文本? - How do I get the currently visible text from a QTextEdit or QPlainTextEdit widget? 如何在不更改QPlainTextEdit类的焦点的情况下检测文本的更改? - How do I detect the change in text without changing the focus in QPlainTextEdit Class? 如何在此输出中的每四个字符之间放置一个空格? - How do I put a space in between every four characters in this output? 如何根据位置删除列表中的特定项目 - How do I remove a specific item in a list based on its position 如何删除QMainWindow和mdiArea之间的空间(边距)? - How to remove space (margin) that between QMainWindow and mdiArea? 在Qt中,如何使对话框不可调整大小,而又自动根据内容调整其大小? - In Qt, how do I make a dialog un-resizeable, yet automatically adjusting its size to the contents?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM