Qt's best way to display very large rich text?

浪尽此生 提交于 2019-12-10 12:58:51

问题


I need to display very large logs that uses HTML tags for marking different types of data.

Using QTextEdit and QTextBrowser really slows the application, especially on append operations. I would really like to keep the QTextEdit interface and abilities.

I've seen people that implemented their own flavor of TextEdit to improve performance, but I wandered if anyone solved this issue using "Qt" tools. I thought about using the Model/View framework to load data on demand but it is not quite what it was intended for I think.

Maybe subclassing QTextEdit and override some of its slots for scrolling...

If anyone encountered this issue and solved it, I would appreciate some tips.

Thanks.


回答1:


Since your log is presumably tabular at some level, then the Model/View framework sounds like it could work for you. Perhaps you could try using a QListView with QGraphicsTextItem:

http://doc.qt.nokia.com/latest/qgraphicstextitem.html

It has methods for setting/getting the HTML:

http://doc.qt.nokia.com/latest/qgraphicstextitem.html#setHtml

http://doc.qt.nokia.com/latest/qgraphicstextitem.html#toHtml

You'll get some benefits and hassles from writing it that way. But you should certainly be able to finesse the insertions and append speed.




回答2:


Use QPlainTextEdit for large log files -- that's what it was designed for. You don't get the full range of options that QTextEdit provides, but you can set the font and the text colour.




回答3:


why not using QWebKit? Module itself is rather heavy, but rendering speed is very good.




回答4:


Since the ROI on re-implementing QTextEdit with the Model/View architecture is low, I will go with @spraff comment on using paging.

Basically I will limit the number of lines I keep in my log, since the log is also dumped into a file, if the user will require something from the past or future (by adding special buttons), I will read it from the file dynamically (lightweight model/view....).



来源:https://stackoverflow.com/questions/6914147/qts-best-way-to-display-very-large-rich-text

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