首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QTableView性能

QTableView性能
EN

Stack Overflow用户
提问于 2018-06-20 08:09:27
回答 1查看 312关注 0票数 1

我用的是QTableView和PyQt5。一旦我开始显示几千行,性能就很糟糕。我尝试了this question的建议,但是Qt框架和QTreeView对我来说并不可行。是否有人对优化QTableView的性能有其他想法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-20 08:16:09

您可以通过实现QTreeViewsetUniformRowHeights来反映sizeHintForRow的效果。

代码语言:javascript
复制
class UniformRowHeights(QTableView):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._row_height = None
    def sizeHintForRow(self, row):
        model = self.model()
        if row < 0 or row >= model.rowCount():
            # Mirror super implementation.
            return -1
        return self.get_row_height()
    def get_row_height(self):
        if self._row_height is None:
            self._row_height = max(self._get_cell_heights())
        return self._row_height
    def changeEvent(self, event):
        # This for instance happens when the style sheet changed. It may affect
        # the calculated row height. So invalidate:
        self._row_height = None
        super().changeEvent(event)
    def _get_cell_heights(self, row=0):
        self.ensurePolished()
        option = self.viewOptions()
        model = self.model()
        for column in range(model.columnCount()):
            index = model.index(row, column)
            delegate = self.itemDelegate(index)
            if delegate:
                yield delegate.sizeHint(option, index).height()
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50943356

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档