python - SelectionModel 和 selectedRows 使用选定的行,但 PyQt4.QtCore.QModelIndex 对象位于 0x12xxxxxx

标签 python pyqt selectionmodel qmodelindex

  def listedensecilensatirlar(self):
      adada = self.ui.tableWidget.selectionModel().selectedRows()
      print adada

我已经选择了我想要实现的每一行中的行,但模型没有读取索引。我选择想要获取的内容作为行中包含的文本数据。

这是我的问题的图片:i.stack.imgur.com/APFPl.png

最佳答案

如果您想从所选行中的项目中获取文本,您可以尝试以下操作:

    indexes = tablewidget.selectionModel().selectedRows(column)
    for index in sorted(indexes):
        row = index.row()
        rowtext = []
        for column in range(tablewidget.columnCount()):
            rowtext.append(tablewidget.item(row, column).text())
        print(rowtext)

但请注意 selectedRows仅获取选择了所有项的行。

关于python - SelectionModel 和 selectedRows 使用选定的行,但 PyQt4.QtCore.QModelIndex 对象位于 0x12xxxxxx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20774395/

相关文章:

python - 在 Python Ubuntu 14.04 中导入 Wand

python - 从 numpy 数据类型获取 python ctypes 数据类型

python - 当 LANG=C 时如何在 Python 2 中打印 Unicode

python - 将 PyQt 转换为 PIL 图像

qt - 如何滚动到QListView中的特定项目?

python - Django 管理站点change_list View 定制

python - 为什么 SLOT ('insertColumn()' ) 在 PyQt 绑定(bind)中失败?

python - 如何使用 selectionModel 在 QTableView 中选择多行

java - JTable.clearSelection() 与 Jtable.getSelectionModel.clearSelection() - 何时使用什么?

java - 自定义 TableViewSelectionModel 未更新