QSortFilterProxyModel and the slot setFilterFixedString

c++, qt

Solution

The column to filter by can be set via QSortFilterProxyModel::filterKeyColumn. It allows to specify a single column, or all of them (-1, the default).

Alternatively, one can define a custom filter role returning a concatenation of all string to search for, and set it via setFilterRole().

Problem

I currently have a search button and I would like to search a specific column of my model.Thus I just want the matching rows to be displayed in my tableview. I have attached a QSortFilterProxyModel* object as a source to the table view and have set a QStandardItemModel* as its source. Then with my search button I made the following connection ``` QObject::connect(ui.lineEditSearch,SIGNAL(textChanged(QString)),proxyModelFilter,SLOT(setFilterFixedString(QString))); ``` Now I was under the impression that upon typing the relevant rows will be returned. Then I realized that I havent specified as to which columns I want the filter proxy model to search. I understand that I could implement a class that inherits from QSortFilterProxyModel and re implement its filterAcceptsRow. I wanted to know if there was a way for me to avoid creating a class that inherits from QSortFilterProxyModel and simply use the QSortFilterProxyModel class only to tell which columns to search on when the Slot setFilterFixedString is called ?

Original source