Python PyQt QTableWidet: How to implement an “adva

2019-09-06 09:22发布

Say there's a QTableWidget filled with a user's data, and he/she wants to be able to perform an "advanced search" on it using multiple user-defined conditional statements: how would one (the programmer, not the user) go about implementing a function in the code that enables the user to perform this search?

For example, let's say the user wants results of the following search:

(column1 > 20 AND column2 < 50) OR column3 = "cloud"

The first approach that comes to mind would be to somehow take the user's search criteria and generate some kind of 'metacode', but I have no idea how this would work.

1条回答
虎瘦雄心在
2楼-- · 2019-09-06 09:53

First you write a parser and then you define a function/grammar column that gives you the content of a column of your table depending on the current row. Then you go through every row, evaluate the parsed expression and return all the rows that evaluated positively.

For more information on how to write a parser see for example Recursive descent parser.

查看更多
登录 后发表回答