python - Use finditem() only on one Column
问题描述
I have a QTableWidget populated with QtableWidgetItems.
I want a searchbar, where I can type in and as Response the Table should be refreshing and only showing the items that match partially with the string in the search field.
Im using finditem for that, but i want that only one column is used for the search. How can I do that?
解决方案
Iterate the table manually.
columnOfInterest = 1 # or whatever
valueOfInterest = "foo"
for rowIndex in range(self.myTable.rowCount()):
twItem = self.myTable.item(rowIndex, columnOfInterest)
if twItem.text() == valueOfInterest:
self.myTable.setRowHidden(rowIndex, False)
else:
self.myTable.setRowHidden(rowIndex, True)
You will have to implement better matching criteria. You can use string functions like str.find
and str.startswith
and others if you want to do it yourself.
推荐阅读
- python - 在 C++/Cython 中,是否可以只声明相关属性在 Python 中可见?
- javascript - 如何在提交表单之前检测输入字段上的 ENTER 键按下?
- flutter - 在 Flutter 中为 showDatePicker 添加标题
- elixir - 长生不老药将标题字符串转换为地图
- java - 将 Java 连接到 SQL 数据库
- python - 为什么 SpaCy 在 Pypi 上不再有版本 <2.0.0 的轮子?
- typescript - 尝试访问我的 lambda 时出现 AWS/Serverless Unknown 错误
- php - Laravel / PHP Unit Test failing after update
- python - Remove elements of a list of lists with another list
- cmake - How to show file download progress with CMake?