Search code examples
pythonpython-3.xpyside2

How to get rows data from a QTableWidget Column?


How can I get the value of each row from a specific column in a QTableWidget?


Solution

  • To get the values of all the rows of a given column then you must iterate by obtaining the QTableWidgetItems using the item() method, verify if it is valid and then get the text.

    col = ...
    
    data = []
    for row in range(tablewidget.rowCount()):
        it = tablewidget.item(row, col)
        text = it.text() if it is not None else ""
        data.append(text)
    print(data)