ayla
ayla

Reputation: 387

Reading selected Items from QTableWidget

How can read selected items from QTableWidget?

Thanks

Upvotes: 6

Views: 22680

Answers (4)

AGo
AGo

Reputation: 304

int QTableWidget::currentRow() const Returns the row of the current item.

int QTableWidget::currentColumn() const Returns the column of the current item.

Upvotes: 6

gseattle
gseattle

Reputation: 1022

Some options (there are also others out there too):

# selectedRanges(), would give you the second cell from each selected row, for example:
indexes = []
for selectionRange in myTable.selectedRanges():
    indexes.extend(range(selectionRange.topRow(), selectionRange.bottomRow()+1))
    print "indexes", indexes      # indexes is a list like [0, 2] of selected rows

for i in indexes:
    print "specific item", myTable.item(i, 1).text()
    results.append( str(myTable.item(i, 1).text()) )

# selectedItems()
for item in myTable.selectedItems():
    print "selectedItems", item.text()

# selectedIndexes()
for item in myTable.selectedIndexes():
    print "selectedIndexes", item.row(), item.column()

Upvotes: 3

Huzy
Huzy

Reputation: 76

the best way to access the items in a qtablewidget is using the function

QList QTableWidget::selectedRanges () const

Upvotes: 0

Patrice Bernassola
Patrice Bernassola

Reputation: 14446

Use the selectedItems function to retrieve the selected items or the selectedIndexes to get all selected cells including empty ones.

Upvotes: 0

Related Questions