Getting started with PySide. I have a specific panel I want to create. Looking good starter content.
-
I have a Python dictionary containing several dictionaries with info about different entities and I want not only to visualize them all as a vertical list, but also to be able to search/filter among the entities attributes to only view the ones that match a criteria. Last but not least it could be nice to have a button on each entry that would then take somewhere with more info on that particular entity.
The image posted shows on the left a list of students with info about them and on the right the same list queried and filtered according to an attribute of the entity entry.
At the moment, I know ZERO PyQt/PySide but in a conversation I was told I could start with tables first, but for the filtering I should be probably go the way of:
- creating a "model" that contains and structures the data I have in those dictionaries.
- create "a view" for instances of those models.
- do a "sort filter proxy model" to control what actually gets passed to the viewer.
Does this check out? If so, what would be rule of thumb places to check out resources about PySide or maybe even something more specific to my goal here? I think I'll need to start small and simple and then gradually add the features I'm after, but appreciate any references to study the most effective way to do what I'm after, in the end.
Will appreciate any keywords I should keep in mind while looking into this or for example if there's a QT Designer template I should look into.
Thanks you!
-
@probiner
I would only recommend theQTableWidget
for speed/convenience/first time. UseQTableView
and an explicit model.If you use a
QStandardItemModel
you will be copying from your Python data to model storage. Which is OK. If you want to get efficient you would/will want to derive fromQAbstractItemModel
so it could /read/write the Python data directly. But that is more work. -
@probiner
Hello and welcome.The first thing I would say is don't get too hooked up on the fact that you are using Python. Whether you use Python/PyQt/PySide/C++ the Qt side is all the same (except for syntax). Qt is written in C++ and all their documentation is for that. There has been some effort to translate some of the docs/examples to Python/PySide, but frankly it's either blindingly obvious or actually does not work! And the PySide docs copy verbatim the explanations from the C++ docs.
Your approach is just right!
- You will want a model. A simple one is
QStandardItemModel
. If you get more advanced you can derive your own fromQAbstractItemModel
. - A
QTableView
will show rows & columns. It can have anyQAbstractItemModel
(includingQStandardItemModel
) as its model. There is also a pre-rolledQTableWidget
which combines a default model plus aQTreeView
for you, but it's nothing you cannot do for yourself and is not as flexible as doing your own, but is quick & convenient. - You can interpose a
QSortFilterProxyModel
between your actual model and theQTreeView
. It will offer sorting and/or filtering of rows shown.
- You will want a model. A simple one is
-
Thank you for confirming the abstract concept and providing keywords for me to look into! :)
I guess my focus on PySide its because its what is offered by the host app. Also the goal is to dynamically generate the entries from selected items in the app. I already have the python script that generates all the data (dictionaries) from the app's selected items. I then need to learn how to fill in the model, I'll try the standard one, with the data from those dictionaries and generate the model instances from it. Anything else to consider about this dynamic aspect?
Concerning the
QTableWidget
convenience, I guess that's why it came up in the conversation as a first go to test. But it sounds like I won't be able to change that "default model" to have all the data about the entry I want, or would I? Also would theQTableWidget
supportQSortFilterProxyModel
to filter out entries?This feels like it's going to take months to grasp, eheh :) Unto the docs!
Thanks
-
@probiner
I would only recommend theQTableWidget
for speed/convenience/first time. UseQTableView
and an explicit model.If you use a
QStandardItemModel
you will be copying from your Python data to model storage. Which is OK. If you want to get efficient you would/will want to derive fromQAbstractItemModel
so it could /read/write the Python data directly. But that is more work. -
@JonB Thanks for the further clarification I think I have enough highlights to get into searching the docs and learning content that touches them.
Cheers
PS: Seems that I must use the
QAbstractItemModel
if I want to useQSortFilterProxyModel
in the end. -
@JonB said in Getting started with PySide. I have a specific panel I want to create. Looking good starter content.:
@probiner
Yes, your ownQAbstractItemModel
, but alsoQStandardItemModel
is already derived from that too.Correct but if I rely on
QStandardItemModel
will I be able to useQSortFilterProxyModel
on it or something to similar end? (Filter entries). No, right? -
@probiner
Wrong, you will be able to useQSortFilterProxyModel
againstQStandardItemModel
. What I pointed out was:QSortFilterProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
means that it can act as a proxy on anyQAbstractItemModel
. The docs tell you thatQStandardItemModel
inheritsQAbstractItemModel
. Therefore QSFPM can accept QSIM as its source model. And if it some point you derive your own model class fromQAbstractItemModel
the proxy will work against that for the same reason. This is what inheritance means in C++ and in Python.