如何从 QTable Widget 中删除多行? [英] How to remove multiple rows from QTable Widget?

查看:87
本文介绍了如何从 QTable Widget 中删除多行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除在 QTableWidget 中选择的多行.任何人都可以有任何想法吗?

I want to remove multiple rows which are selected in the QTableWidget . can anyone have any ideas ?

推荐答案

您可以一次删除多个项目,提示,是从底部开始删除行.抱歉,我不是 VS2008 开发人员,但此解决方案可以轻松转换为 VS2008 代码.这里是 Python 代码.抱歉回复晚了:)

You can remove multiple items at once, The tips, is begin delete the rows from the bottom. i'm sorry im not a VS2008 developer, but this solution can be easy convert to VS2008 code. Here the Python code. Sorry for the late response :)

# Delete the selected mytable lines
deleteRows(self.mytable.selectionModel().selectedRows())

# DeleteRows function
def deleteRows(self, rows):
        # Get all row index
        indexes = []
        for row in rows:
            indexes.append(row.row())

        # Reverse sort rows indexes
        indexes = sorted(indexes, reverse=True)

        # Delete rows
        for rowidx in indexes:
            self.mytable.removeRow(rowidx)

这篇关于如何从 QTable Widget 中删除多行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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