Qt 显示非常大的富文本的最佳方式?
我需要显示非常大的日志,该日志使用 HTML 标签来标记不同类型的数据。
使用 QTextEdit 和 QTextBrowser 确实会减慢应用程序的速度,尤其是在附加操作上。我真的很想保留 QTextEdit 界面和功能。
我见过有人实现了自己风格的 TextEdit 来提高性能,但我想知道是否有人使用“Qt”工具解决了这个问题。我考虑过使用模型/视图框架来按需加载数据,但这并不完全符合我的预期。
也许子类化 QTextEdit 并覆盖它的一些滚动槽...
如果有人遇到这个问题并解决它,我将不胜感激一些提示。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用
QPlainTextEdit
来处理大型日志文件——这就是它的设计目的。您无法获得QTextEdit
提供的全部选项,但您可以设置字体和文本颜色。Use
QPlainTextEdit
for large log files -- that's what it was designed for. You don't get the full range of options thatQTextEdit
provides, but you can set the font and the text colour.由于您的日志在某种程度上可能是表格形式的,因此模型/视图框架听起来适合您。也许您可以尝试使用
QListView
和 QGraphicsTextItem ,它有设置/获取 HTML 的方法:你会从写作中得到一些好处和麻烦就这样,但您当然应该能够巧妙地插入和追加速度。
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, It has methods for setting/getting HTML: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.
为什么不使用QWebKit?模块本身比较重,但是渲染速度非常好。
why not using
QWebKit
? Module itself is rather heavy, but rendering speed is very good.由于使用模型/视图架构重新实现 QTextEdit 的投资回报率较低,因此我将同意 @spraff 关于使用分页的评论。
基本上我会限制日志中保留的行数,因为日志也会转储到文件中,如果用户需要过去或将来的某些内容(通过添加特殊按钮),我将从文件中动态读取它(轻量级模型/视图......)。
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....).