Qt Snippet: Remove all rows from QTableWidget

QTableWidget is the Qt widget that, as the name suggest, show a table composed by cells able to contain both native field like text or icon and also more complex widgets like listbox, checkbox and so on.




Usually for Qt list widgets the method clear() remove all the rows currently showed in the control. However, also if present, this call doesn't work for QTableWidget control. If you want to remove all the rows from QTableWidget you need to simply set the number of rows to zero as follow:

MyTable->setRowCount(0);

This will have same effect of clear() and remove all rows.

Comments

  1. clear() sort of works with QTableWidgets (PyQt5). It removes the data, but leaves blank lines.

    Using setRowCount() and horizontalHeader().setVisible(True/False) and setHorizontalHeaderLabels(array) lets me make the app look and behave exactly as I want.

    Thanks

    ReplyDelete

Post a Comment

Popular posts from this blog

Access GPIO from Linux user space

Android: adb push and read-only file system error

Tree in SQL database: The Nested Set Model