Reading selected Items from QTableWidget

Deadly 提交于 2019-11-30 15:45:55

问题


How can read selected items from QTableWidget?

Thanks


回答1:


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()



回答2:


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

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




回答3:


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




回答4:


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

QList QTableWidget::selectedRanges () const



来源:https://stackoverflow.com/questions/2786857/reading-selected-items-from-qtablewidget

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!