How to most efficiently implement a PySide QListView/QAsbtractItemView for an SQLAlchemy table?

痞子三分冷 提交于 2019-12-25 13:29:27

问题


Suppose I have a class Client (subclassing sqlalchemy.ext.declarative.declarative_base), giving me an SQL table of clients. Each client has

  1. a name,
  2. a number and
  3. an image path.

(Of course there are more variables in real)

What I want, is a vertical list of panels in my GUI, where each panel includes the client's image, name and number. The panel should

  • be clickable and
  • show an optical response OnMouseOver.

Further, the list of these items should allow to be

  • reordered (e.g. by number, surname, ...) and
  • filtered (e.g. by surnames starting with "A").

Of course everything should be as efficient as possible :)

Implementation

In the past, I tried to do it very naively, using a QWidget with QVBoxLayout, adding each of the panels (subclass of QFrame) using addWidget(). When I applied a filter, I removed all the panels and added the filtered ones again in the desired order. Of course, this cannot be the best solution, since it is very inefficient and difficult to update, etc.

I guess, using a QListView with an underlying QAbstractListModel would be much better. Or maybe even QAbstractItemView/QAbstractItemModel?

Could anyone push me to the right direction and give some comments/suggestions on how to optimally implement the described behavior? I would be grateful!

来源:https://stackoverflow.com/questions/33253745/how-to-most-efficiently-implement-a-pyside-qlistview-qasbtractitemview-for-an-sq

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