【问题标题】:Performance problems with showing large text files using TextArea and ScrollView使用 TextArea 和 ScrollView 显示大文本文件的性能问题
【发布时间】:2020-02-21 13:29:21
【问题描述】:

用例: 我想使用 QML 或至少与 QML 兼容的组件来显示大型日志文件(8k+ 行)。多行选择、复制和语法突出显示等功能是强制性的。

问题: 默认方法是在 ScrollView 中使用 TextArea,但问题是内存使用率高(在我的机器上选择了多行:2GB+)导致冻结(5sec+)和崩溃。

示例代码:

import QtQuick 2.12
import QtQuick.Controls 2.5
ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("TextEditTest")
    ScrollView {
        id: scrollView
        anchors.fill: parent

        TextArea {
            id: textArea
            text: " "
            renderType: Text.NativeRendering
            textFormat: Text.PlainText
            placeholderText: "no text found"
            readOnly: true
            selectByMouse: true
        }
    }
}

(只需在“”中插入一些文本(8k+ 行))

问题: 是否可以提高 TextArea + ScrollView 的内存使用率?或者有其他选择吗?

可能的解决方案?:仍然使用 TextEdit,但提供了一个自己的滚动功能,可以按需加载文本,从而防止一次渲染整个文本。问题是我必须在现有的基础上编写自己的选择和复制功能。

【问题讨论】:

    标签: qt qml desktop-application qtquick2


    【解决方案1】:

    This comment from Jira总结问题并提供可能的解决方案:

    Qt Quick 的 TextEdit 实际上会为场景图填充所有字形的节点,而不仅仅是可见的。有逻辑可以尽可能地隔离更新,但所有文本的所有几何图形都必须至少处理一次并上传到 GPU,并为其生成绘制调用。

    所以底线是 TextEdit 目前不适合这种大小的文本。在解决此问题之前,我建议改用 QQuickPaintedItem 和 QTextDocument。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-09
      • 2021-03-19
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 2021-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多