Reputation: 1428
I am trying to filter a QTableView based on text in QLineEdit by using a QSortFilterProxyModel. It is working, although not correctly - it is not displaying items that are a "complete match". An example will better illustrate what I mean.
Example: Typing "22" into the QLineEdit will show rows that have "22" in the first column, but not the row that has a column that is equal to 22. "229" will be shown, "2224" will be shown, but not "22"
Below is the stripped down version of my code
self.model = QSqlTableModel()
self.model.setTable("products")
self.model.select()
self.proxy = QSortFilterProxyModel()
self.proxy.setSourceModel(self.model)
self.proxy.setFilterKeyColumn(0)
self.ui.table_products.setModel(self.proxy)
self.ui.line_input.textChanged.connect(self._filter_products)
def _filter_products(self, text):
search = QRegExp(
text,
Qt.CaseInsensitive,
QRegExp.RegExp
)
self.proxy.setFilterRegExp(search)
Upvotes: 2
Views: 668
Reputation: 4626
It looks to me like you are filtering on column 0...
self.proxy.setFilterKeyColumn(0)
...and there is only 1 row with 22 in that column.
Upvotes: 1