問題描述
QTextEdit
和 QPlainTextEdit
有什么區別,為什么要使用一個?
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
是一個瘦類,使用大部分QTextEdit
和 QTextDocument
背后的技術.它的性能優于 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模板網!