QTextEdit 与 QPlainTextEdit

时间:2023-01-22
本文介绍了QTextEdit 与 QPlainTextEdit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

QTextEditQPlainTextEdit 有什么区别,为什么要使用一个?

What's the difference between QTextEdit and QPlainTextEdit, why use one over the other?

我正在编写一个文本编辑器作为学习 Qt5 的练习,现在我想知道是使用 QTextEdit 还是 QPlainTextEdit.到目前为止,我只发现您可以在 QTextEdit 中显示图像,但除此之外,它们对我来说看起来有些相同.我的文本编辑器应该支持一些基本的语法高亮显示(可能使用 textChanged() 信号),但就需求而言就差不多了.

I'm coding a text editor as an exercice to learn Qt5, and now I'm wondering whether to use QTextEdit or QPlainTextEdit. So far I've only found out that you can display images in QTextEdit, but other than that they look somewhat identical to me. My text editor should support some basic syntax highlighting (probably using textChanged() signal), but that's pretty much as far as the requirements go.

Google 搜索QTextEdit vs QPlainTextEdit"QTextEdit 与 QPlainTextEdit 相比" 没有给我任何可以比较这两个类的不错的结果.

Google searches for "QTextEdit vs QPlainTextEdit" and "QTextEdit compared to QPlainTextEdit" didn't give me any decent results that would compare the two classes.

推荐答案

来自 Qt 的文档:

QPlainTextEdit 是一个支持纯文本的高级查看器/编辑器.它经过优化以处理大型文档并快速响应用户输入.

QPlainTextEdit is an advanced viewer/editor supporting plain text. It is optimized to handle large documents and to respond quickly to user input.

QPlainText 使用的技术和概念与QTextEdit,但针对纯文本处理进行了优化.

QPlainText uses very much the same technology and concepts as QTextEdit, but is optimized for plain text handling.

QPlainTextEdit 适用于段落和字符.一个段落是一个被自动换行以适应宽度的格式化字符串小部件.默认情况下,在阅读纯文本时,换行符表示段落.一个文档由零个或多个段落组成.段落由硬换行符分隔.段落中的每个字符有自己的属性,例如字体和颜色.

QPlainTextEdit works on paragraphs and characters. A paragraph is a formatted string which is word-wrapped to fit into the width of the widget. By default when reading plain text, one newline signifies a paragraph. A document consists of zero or more paragraphs. Paragraphs are separated by hard line breaks. Each character within a paragraph has its own attributes, for example, font and color.

后来:

与 QTextEdit 的区别

QPlainTextEdit 是一个瘦类,使用大部分QTextEditQTextDocument 背后的技术.它的性能优于 QTextEdit 的好处主要来自于使用不同的和在文本上称为 QPlainTextDocumentLayout 的简化文本布局文档(见 QTextDocument::setDocumentLayout()).纯文本文档布局不支持表格或嵌入式框架,并且用逐行替换像素精确高度计算分别是逐段滚动的方法.这使它可以处理明显更大的文档,并且仍然可以调整大小实时启用换行的编辑器.这也使得一个快速日志查看器(请参阅 setMaximumBlockCount()).

QPlainTextEdit is a thin class, implemented by using most of the technology that is behind QTextEdit and QTextDocument. Its performance benefits over QTextEdit stem mostly from using a different and simplified text layout called QPlainTextDocumentLayout on the text document (see QTextDocument::setDocumentLayout()). The plain text document layout does not support tables nor embedded frames, and replaces a pixel-exact height calculation with a line-by-line respectively paragraph-by-paragraph scrolling approach. This makes it possible to handle significantly larger documents, and still resize the editor with line wrap enabled in real time. It also makes for a fast log viewer (see setMaximumBlockCount()).

所以区别在于 QPlainTextEdit 针对处理纯文本进行了优化,甚至可以用于处理非常大的纯文本文件.文本的格式化方式也更简单.

So the difference is that QPlainTextEdit is optimized for handling plain text, and can be used even with very large plain text files. Also the way text is formatted is simpler.

如果您打算只支持纯文本,那么 QPlainTextEdit 是正确的选择.

If you plan to support only plain texts, then QPlainTextEdit is the right choice.

这篇关于QTextEdit 与 QPlainTextEdit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:QMetaObject::connectSlotsByName: 没有匹配的信号 下一篇:Qt - 确定绝对小部件和光标位置

相关文章

最新文章