Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Getting started with PySide. I have a specific panel I want to create. Looking good starter content.
Forum Updated to NodeBB v4.3 + New Features

Getting started with PySide. I have a specific panel I want to create. Looking good starter content.

Scheduled Pinned Locked Moved Solved Qt for Python
pyside2
8 Posts 2 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    probiner
    wrote on last edited by probiner
    #1

    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.

    alt text

    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:

    1. creating a "model" that contains and structures the data I have in those dictionaries.
    2. create "a view" for instances of those models.
    3. 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!

    JonBJ 1 Reply Last reply
    0
    • P probiner

      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 the QTableWidget support QSortFilterProxyModel to filter out entries?

      This feels like it's going to take months to grasp, eheh :) Unto the docs!

      Thanks

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #4

      @probiner
      I would only recommend the QTableWidget for speed/convenience/first time. Use QTableView 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 from QAbstractItemModel so it could /read/write the Python data directly. But that is more work.

      P 1 Reply Last reply
      1
      • P probiner

        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.

        alt text

        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:

        1. creating a "model" that contains and structures the data I have in those dictionaries.
        2. create "a view" for instances of those models.
        3. 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!

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #2

        @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!

        1. You will want a model. A simple one is QStandardItemModel. If you get more advanced you can derive your own from QAbstractItemModel.
        2. A QTableView will show rows & columns. It can have any QAbstractItemModel (including QStandardItemModel) as its model. There is also a pre-rolled QTableWidget which combines a default model plus a QTreeView for you, but it's nothing you cannot do for yourself and is not as flexible as doing your own, but is quick & convenient.
        3. You can interpose a QSortFilterProxyModel between your actual model and the QTreeView. It will offer sorting and/or filtering of rows shown.
        1 Reply Last reply
        2
        • P Offline
          P Offline
          probiner
          wrote on last edited by probiner
          #3

          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 the QTableWidget support QSortFilterProxyModel to filter out entries?

          This feels like it's going to take months to grasp, eheh :) Unto the docs!

          Thanks

          JonBJ 1 Reply Last reply
          0
          • P probiner

            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 the QTableWidget support QSortFilterProxyModel to filter out entries?

            This feels like it's going to take months to grasp, eheh :) Unto the docs!

            Thanks

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #4

            @probiner
            I would only recommend the QTableWidget for speed/convenience/first time. Use QTableView 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 from QAbstractItemModel so it could /read/write the Python data directly. But that is more work.

            P 1 Reply Last reply
            1
            • JonBJ JonB

              @probiner
              I would only recommend the QTableWidget for speed/convenience/first time. Use QTableView 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 from QAbstractItemModel so it could /read/write the Python data directly. But that is more work.

              P Offline
              P Offline
              probiner
              wrote on last edited by probiner
              #5

              @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 use QSortFilterProxyModel in the end.

              9e20fc58-ee2c-42cd-aa14-426b3a71f94e-image.png

              JonBJ 1 Reply Last reply
              0
              • P probiner

                @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 use QSortFilterProxyModel in the end.

                9e20fc58-ee2c-42cd-aa14-426b3a71f94e-image.png

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #6

                @probiner
                Yes, your own QAbstractItemModel, but also QStandardItemModel is already derived from that too.

                P 1 Reply Last reply
                0
                • JonBJ JonB

                  @probiner
                  Yes, your own QAbstractItemModel, but also QStandardItemModel is already derived from that too.

                  P Offline
                  P Offline
                  probiner
                  wrote on last edited by probiner
                  #7

                  @JonB said in Getting started with PySide. I have a specific panel I want to create. Looking good starter content.:

                  @probiner
                  Yes, your own QAbstractItemModel, but also QStandardItemModel is already derived from that too.

                  Correct but if I rely on QStandardItemModel will I be able to use QSortFilterProxyModel on it or something to similar end? (Filter entries). No, right?

                  JonBJ 1 Reply Last reply
                  0
                  • P probiner

                    @JonB said in Getting started with PySide. I have a specific panel I want to create. Looking good starter content.:

                    @probiner
                    Yes, your own QAbstractItemModel, but also QStandardItemModel is already derived from that too.

                    Correct but if I rely on QStandardItemModel will I be able to use QSortFilterProxyModel on it or something to similar end? (Filter entries). No, right?

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #8

                    @probiner
                    Wrong, you will be able to use QSortFilterProxyModel against QStandardItemModel. What I pointed out was: QSortFilterProxyModel::setSourceModel(QAbstractItemModel *sourceModel) means that it can act as a proxy on any QAbstractItemModel. The docs tell you that QStandardItemModel inherits QAbstractItemModel. Therefore QSFPM can accept QSIM as its source model. And if it some point you derive your own model class from QAbstractItemModel the proxy will work against that for the same reason. This is what inheritance means in C++ and in Python.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved