【问题标题】:Getting Selected Rows Count in QTableWidget - PyQt在 QTableWidget 中获取选定的行数 - PyQt
【发布时间】:2017-03-21 18:40:39
【问题描述】:

在pythonplugin中,我正在开发,我需要在QTableWidget中检索选定的行数。我可以遍历QTableWidget 的每一行并检查它们是否被选中。相反,是否有一种简单的方法可以在PyQt 中获取QTableWidget 的选定行数?

类似:

QTableWidget.selectedRowsCount()

【问题讨论】:

  • 您的选择行为是什么?是设置为 SelectItems 还是 SelectRows?
  • @BrendanAbel 是selectedRows(点击行头时的行选择)

标签: python pyqt qtablewidget


【解决方案1】:

如果您想要完全选中的行数(即,当单击行标题时):

len(tableWidget.selectionModel().selectedRows())

但是,如果您想要只有 至少一个单元格被选中的行:

len(set(index.row() for index in tableWidget.selectedIndexes()))

【讨论】:

  • 成功了!! len(tableWidget.selectionModel().selectedRows()) 是我需要的(选择整行)。
【解决方案2】:

len(tablewidget.selectedIndexes()) 应该可以做你想做的事。

【讨论】:

    猜你喜欢
    • 2016-03-19
    • 2016-03-26
    • 1970-01-01
    • 2013-05-11
    • 1970-01-01
    • 1970-01-01
    • 2011-01-04
    • 2018-06-01
    • 2019-05-14
    相关资源
    最近更新 更多