Python PyQt QTableWidet: How to implement an “advanced search” function

早过忘川 提交于 2019-12-11 14:32:57

问题


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:


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.



来源:https://stackoverflow.com/questions/25691990/python-pyqt-qtablewidet-how-to-implement-an-advanced-search-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!