【发布时间】: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