How to end line with QTextEdit

冷暖自知 提交于 2019-12-20 01:45:27

问题


I'm trying to create QTextEdit with some text, and in this text I have end of line characters (\n), but it is not accepted in QTextEdit object (whole text is displayed without any breaks). Any reason why?


回答1:


If you're using Qt 4.3 or later, then you can use setPlainText(const QString &text)

You can turn off rich text editing with setAcceptRichText(bool accept) (Qt 4.1 or later)




回答2:


Per the docs, if you setTextFormat(PlainText) you should get what you want -- quoting with added emphasis:

QTextEdit 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 signify a paragraph. A document consists of zero or more paragraphs, indexed from 0. Characters are indexed on a per-paragraph basis, also indexed from 0. The words in the paragraph are aligned in accordance with the paragraph's alignment(). Paragraphs are separated by hard line breaks. Each character within a paragraph has its own attributes, for example, font and color.



来源:https://stackoverflow.com/questions/2173151/how-to-end-line-with-qtextedit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!