I HIGHLY recommend going about this in the following way! This is how it is meant to be done in Qt.
Look at the tutorial on Qt Model/View Programming. The problem is that QTableWidget is a convenience class that hides the Model/View stuff for you. In your case, you can't (or shouldn't) ignore the Model/View structure Qt provides.
What you will need to do:
- Use a
QTableView
instead of a QTableWidget
.
- Subclass
QAbstractItemModel
and implement data()
(for reading), and all the other functions you need from the documentation. This is the trickiest part, but refer to the above link for a walkthrough of how to do this.
- Create a
QSortFilterProxyModel
and setModel()
of the QTableView
to it.
setSourceModel()
of your QSortFilterProxyModel
to your subclassed model.
- Set the string you want to filter on using
setFilterFixedString()
or setFilterRegExp()
in your QSortFilterProxyModel
Let me know if this helps. This is far more professional, and in the long run, elegant, than iterating through all the elements in your table.