本文介绍了Python PyQt QTableWidet:如何实现“高级搜索"功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有一个填充了用户数据的 QTableWidget,并且他/她希望能够使用多个用户定义的条件语句对其执行高级搜索":一个人(程序员,而不是用户)将如何去关于在代码中实现一个功能,使用户能够执行此搜索?

例如,假设用户想要以下搜索的结果:

(column1 > 20 AND column2 

想到的第一种方法是以某种方式采用用户的搜索条件并生成某种元代码",但我不知道这是如何工作的.

解决方案

首先你写一个 parser 然后你定义一个函数/语法 column ,它给你的内容表的一列取决于当前行.然后遍历每一行,评估解析后的表达式并返回所有评估为正的行.

有关如何编写解析器的更多信息,请参见例如递归下降解析器.>

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.

解决方案

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.

这篇关于Python PyQt QTableWidet:如何实现“高级搜索"功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 04:00