Qt 实现 Logger 日志的显示
程序员文章站
2022-06-01 20:00:17
...
转自http://doc.okbase.net/gongshang/archive/117406.html
要求: 能够控制显示的总共行数。但不想要太重量级,简单显示就好。
参考*
使用QPlainTextEdit
If you want to limit the total number of paragraphs in a QPlainTextEdit, as it is for example useful in a log viewer, then you can use the maximumBlockCount property. The combination of setMaximumBlockCount() and appendPlainText() turns QPlainTextEdit into an efficient viewer for log text. The scrolling can be reduced with the centerOnScroll() property, making the log viewer even faster. Text can be formatted in a limited way, either using a syntax highlighter (see below), or by appending html-formatted text with appendHtml(). While QPlainTextEdit does not support complex rich text rendering with tables and floats, it does support limited paragraph-based formatting that you may need in a log viewer.
组合 setMaximumBlockCount() 和 appendPlainText() 方法,来实现logger的显示,可以控制总共显示的行数。
有点是更轻量级
缺点是没有太好的办法去高亮显示Error,Warning等。
缺点,进行筛选相对麻烦
使用 QListWidget 或者 QTableWidget
可以设置总行数来控制显示的日志数量。
缺点,相对后重点
优点,可以方便的用不同颜色高亮Error,Warning等。
快速实现
可参考Qt之日志输出文件,相对容易实现点。
原文链接:http://my.oschina.net/gongshang/blog/353590
要求: 能够控制显示的总共行数。但不想要太重量级,简单显示就好。
参考*
使用QPlainTextEdit
If you want to limit the total number of paragraphs in a QPlainTextEdit, as it is for example useful in a log viewer, then you can use the maximumBlockCount property. The combination of setMaximumBlockCount() and appendPlainText() turns QPlainTextEdit into an efficient viewer for log text. The scrolling can be reduced with the centerOnScroll() property, making the log viewer even faster. Text can be formatted in a limited way, either using a syntax highlighter (see below), or by appending html-formatted text with appendHtml(). While QPlainTextEdit does not support complex rich text rendering with tables and floats, it does support limited paragraph-based formatting that you may need in a log viewer.
组合 setMaximumBlockCount() 和 appendPlainText() 方法,来实现logger的显示,可以控制总共显示的行数。
有点是更轻量级
缺点是没有太好的办法去高亮显示Error,Warning等。
缺点,进行筛选相对麻烦
使用 QListWidget 或者 QTableWidget
可以设置总行数来控制显示的日志数量。
缺点,相对后重点
优点,可以方便的用不同颜色高亮Error,Warning等。
快速实现
可参考Qt之日志输出文件,相对容易实现点。
原文链接:http://my.oschina.net/gongshang/blog/353590
上一篇: Qt中使用的C++知识和技能 qtc++
下一篇: QT入门学习笔记3 - 创建对话框