[英]PyQt4 QTableWidget - Filter and modify data from a mySQL database
I'm new to PyQt4 and I'm wondering how to filter QTableWidget data pulled from a MySQL database. 我是PyQt4的新手,我想知道如何过滤从MySQL数据库提取的QTableWidget数据。 I was using a QSqlTableModel and I could filter that data easily but I don't like to update the database through a QSqlTableModel.
我使用的是QSqlTableModel,可以轻松过滤该数据,但我不喜欢通过QSqlTableModel更新数据库。 Essentially, I would like the QTableWidget to automatically re-populate as I type search data.
本质上,我希望QTableWidget在键入搜索数据时自动重新填充。 I looked at an example in PyQt4 on my Windows machine called "Basic Sort/Filter Model."
我在Windows机器上的PyQt4中查看了一个名为“基本排序/过滤器模型”的示例。 It does what I want, however, the example uses a QTreeView and I'm using a QTableWidget.
它可以实现我想要的功能,但是该示例使用了QTreeView,而我使用的是QTableWidget。 Any help would be appreciated.
任何帮助,将不胜感激。
In order to filter data you need to wrap your model in a QSortFilterProxyModel . 为了过滤数据,您需要将模型包装在QSortFilterProxyModel中 。 The QTableWidget uses a default model that you can't change, so to use the QSortFilterProxyModel you need to use a QTableView instead.
QTableWidget使用无法更改的默认模型,因此要使用QSortFilterProxyModel,您需要使用QTableView 。
Here is a tutorial on how to use the QSortFilterProxyModel. 这是有关如何使用QSortFilterProxyModel的教程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.