I’m writing a little program with PyQt5 which shows a QTableView containing datas from a list of D&D items, to which I applied a filtering QSortFilterProxyModel.
One of the columns contains the characteristics of the item in the first column (i.e., ‘Ammunition, Heavy, Range, Reach, Special’), and I’m having trouble writing the correct filtering.
The user can select which characteristics they wanna choose with a QDialog, which returns a list with the chosen selection, and the program should filter the items according to it.
If I just select one of the characteristics among 20, everything’s fine:
char_list = self.dialog.returnvalues()
characteristic = char_list[0]
self.proxy.setFilterKeyColumn(7)
self.proxy.setFilterRegExp(QRegExp(characteristic))
and I get what I want, but if I want to select two, I have no idea how to write the proper QRegExp to give to the proxy.setFilterRegExp to obtain the filtering I would like.
I checked online, and I found something like ‘characteristic1|characteristic2’ should to the trick, so I tried:
characteristic = '|'.join(char_list)
which works but not the way I want, because the pipe is like the OR operator, and I need AND (only an item with both or more characteristics should be selected, not if it has just one of them).
The main problem is that I’m still learning Python and PyQt, I know basically nothing of C++, so most of the times I don’t really know how to translate the Qt documentation or to adjust the examples I find online to my system.
Can someone help me please?