qt create tablewidget 指定列查询字符,将符合条件的行显示
时间: 2024-01-25 10:04:20 浏览: 105
您可以使用QTableWidget的findItems()函数来查找符合条件的单元格,并使用QTableWidget的setRowHidden()函数来隐藏或显示符合条件的行。
以下是示例代码:
```python
# 假设您的QTableWidget对象名为tableWidget,您要查找的列为第1列,您要查找的字符串为"example"
matching_items = tableWidget.findItems("example", Qt.MatchContains, 1)
for item in matching_items:
row = item.row()
tableWidget.setRowHidden(row, False) # 显示符合条件的行
# 隐藏不符合条件的行
for i in range(tableWidget.rowCount()):
if not tableWidget.isRowHidden(i):
if len(tableWidget.findItems("example", Qt.MatchContains, 1)) == 0:
tableWidget.setRowHidden(i, True)
```
这段代码将会查找第1列中包含字符串"example"的单元格,并显示符合条件的行,同时隐藏不符合条件的行。注意,这段代码只会查找第一次出现的符合条件的单元格,如果有多个单元格符合条件,只会显示第一个符合条件的行。如果您需要查找所有符合条件的单元格,可以使用QTableWidget的item()函数和QTableWidgetItem的text()函数来遍历每个单元格。
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![7z](https://img-home.csdnimg.cn/images/20241231044736.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)