1

I have 3 comboboxes and a QTableView widget with 3 columns. I want to filter each of these columns by selected option in combobox connected to it. I know how to do it for just one column with setFilterKeyColumn() method, but how to achieve the same result for more comboboxes? I obviously want all the filters to be active at the same time.
This is my example for 1 connected column

    self.cb1 = QComboBox()
    self.cb2 = QComboBox()
    self.cb3 = QComboBox()
    model = QStandardItemModel(5, 3)
    # skipped the model populating code
    filter_proxy_model = QSortFilterProxyModel()
    filter_proxy_model.setSourceModel(model)
    filter_proxy_model.setFilterKeyColumn(1)

    self.cb1.currentTextChanged.connect(filter_proxy_model.setFilterFixedString)
    table = QTableView()
    table.setModel(filter_proxy_model)
user430953
  • 191
  • 2
  • 19
  • 1
    Mmmh, if you want to filter with a three column criteria, you should clarify how the column filtering should work; the basic behavior of the QSortFilterProxyModel applied to a column works by showing a *row* if and only if filter applies to the cell at that row, for the selected key column. This kind of filtering is considered as an *AND* operator (as in: show the row if *all* filters apply), but you might want an *OR* operator (show the row if *any* of the filters applies). In any way, you can accomplish this only by subclassing. – musicamante Apr 18 '20 at 21:34
  • @musicamante Yes, I want all criteria to be met - so AND operator. I was hoping there would be an easier option as I am just learning, but alas – user430953 Apr 18 '20 at 22:12

0 Answers0