How to add new row to existing QTableWidget?

Viewed 71879

My app is phonebook(educational purposes). When user opens application, QTableWidged is filled with data loaded from .xml file. When user add new phone number, I would like to append this number to QTableWidget, but previously I setRowCount to current value, and now it is one row to little. How can I solve this problem?

3 Answers

If you are using Python + PyQt5

from PyQt5 import QtCore, QtWidgets

# table is a QtWidgets.QTableWidget object
table.insertRow(table.rowCount()) 
item = QtWidgets.QTableWidgetItem(ITEM_CONTENT)
table.setItem(table.rowCount()-1, COLUMN_INDEX, item)
item = QtWidgets.QTableWidgetItem(ROW_LABEL_STRING)
table.setVerticalHeaderItem(table.rowCount()-1, item)
Related