emreddogan
emreddogan

Reputation: 33

selectionModel and selectedRows used selected rows but PyQt4.QtCore.QModelIndex object at 0x12xxxxxx

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

I have chosen the line in each row I want to achieve but the model did not read the index. I choose what I want to get as text data contained in rows.

This is a picture of my problem: https://i.sstatic.net/APFPl.png

Upvotes: 2

Views: 5115

Answers (3)

LexShev
LexShev

Reputation: 1

num = 0  # number of columns
items = self.ui.tableWidget.selectionModel().selectedRows(num)
row_text = [item.data() for item in items]

Upvotes: 0

다크매터
다크매터

Reputation: 81

There is a good answer on the top, but try this one too.

indexRows = table.selectionModel().selectedRows()
for indexRow in sorted(indexRows):
    row = indexRow.row()
rowText = table_model.item(row, column=number).text()
print(rowText)

Upvotes: 0

ekhumoro
ekhumoro

Reputation: 120608

If you want to get the text from the items in the selected rows, you could try this:

    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)

But note that selectedRows only get rows where all items are selected.

Upvotes: 3

Related Questions