您的位置:首页 > 博客中心 > 互联网 >

Qt 实现 Logger 日志的显示

时间:2022-04-23 04:15

要求: 能够控制显示的总共行数。但不想要太重量级,简单显示就好。

参考

使用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等。

快速实现

可参考,相对容易实现点。

本类排行

今日推荐

热门手游