Qt小部件,用于显示大量数据行 [英] Qt widget for displaying large amount of data rows

查看:703
本文介绍了Qt小部件,用于显示大量数据行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Qt(5.1)在可滚动视图中显示大量列式记录.

I am trying to display a large amount of columnar records in a scrollable view using Qt (5.1).

例如,我希望能够浏览的行数可以从1亿到10亿不等.

The number of rows I would like to be able to browse can vary from 100 million to 1 Billion, say.

具有自定义模型的QTableWidget可以处理几百万行,但是QTableWidget会为每一行分配数据,因为您可以调整行高的大小,因此它必须为此存储数据,这可能会使用兆字节甚至千兆字节的数据.具有100M行的内存.

The QTableWidget with a custom model works a few million rows, but the QTableWidget allocates data for each row because you can re-size the rows height, and so it must store data for this, which can use megabytes or even gigabytes of memory with 100M rows.

我不需要可调整大小的行功能,只是多列列表将是理想选择,但是QTreeCtrl似乎不适用于许多行,并且QList似乎仅支持单列.

I do not require the re-sizeable rows functionality just a multi-column list would be ideal, but QTreeCtrl doesnt seem to work with many rows, and QList seems to only support single columns.

我是否应该为此目的从QAbstractItemView实现自定义窗口小部件?

Should I be implementing a custom widget from QAbstractItemView for this purpose?

对于那些熟悉wxwidgets/wepython的人来说,可以这样完成,并且可以处理数十亿行:

For those familiar with wxwidgets/wepython it can be done like this, and works well with billions of rows:

import wx

class VirtualList(wx.ListCtrl):

    def __init__(self, parent, id, pos, size, flags):
        wx.ListCtrl.__init__(self, parent, id, pos, size, flags)

    def OnGetItemText(self, item, column):
        return "Row %d, Column %d" % (item, column)

推荐答案

如果是表格数据,我将使用一个表.我将使用自定义QAbstractTableModel编写自定义QTableView.在QTableView中,您可以控制所有可见项.我将在QTableView及其模型之间共享某种检查或变量,以控制应显示多少数据.通过重写QAbstractTableModel中的data方法,您可以决定要显示多少数据.您还可以将QTableView的滚动条弄乱,使外观看起来更好.

If it's tabular data I would use a table. I would write a custom QTableView with a custom QAbstractTableModel. In the QTableView you have control of all visible items. I would put some kind of check or variable shared between QTableView and it's model to control how much data should be shown. By overriding the data method in QAbstractTableModel you can dictate how much data to show. You can also mess with the QTableView's scroll bar to make things look and feel nicer.

如果您不太在意编辑或外观,则可以使用设置为只读的简单QTextEdit/QTextBrowser.

If you don't really care about editing or looks, you could use a simple QTextEdit/QTextBrowser that is set to read only.

注意:具有自定义模型的QTableWidget有点毫无意义. QTableWidget和QTableView之间的主要区别在于QTableWidget具有自己的预制模型.

Note: A QTableWidget with a custom model is somewhat pointless. The main difference between a QTableWidget and a QTableView is that the QTableWidget has it's own premade model.

这篇关于Qt小部件,用于显示大量数据行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆