Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Model view widget with different root item ?
QtWS25 Last Chance

Model view widget with different root item ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qstandarditemmoqtreeviewqabstractitemmo
9 Posts 3 Posters 1.5k 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.
  • D Offline
    D Offline
    Dariusz
    wrote on 14 Mar 2019, 20:01 last edited by
    #1

    Hey

    Say I have a model with these items

    invisibleRoot
        groupA
             itA
        groupB 
             it1
        groupC
             icA1
    

    say right now the treeView would display 3 groupsA-C and their children. Is there a way to filter the view to only display either groupA/-C or bothA+B / etc etc?

    Regards
    Dariusz

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 14 Mar 2019, 20:33 last edited by
      #2

      Hi,

      You can add a QSortFilterProxyModel and filter out the groups you don't want to show.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • D Offline
        D Offline
        Dariusz
        wrote on 14 Mar 2019, 21:35 last edited by
        #3

        Yup thats it ! Thanks!

        A small follow up tho... so we don't waste the topic totally...

        Can proxyModel display a dataset from different models?

        So
        QStandardItemModelA
        QStandardItemModelB
        QStandardItemModelC

        QProxyModel.setModel({QStandardItemModelA,QStandardItemModelB,QStandardItemModelC})
        QTreeView.setModel(proxy)

        ??
        TIA

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 14 Mar 2019, 21:48 last edited by
          #4

          No, that's something you would have to implement in your own custom subclass of QAbstractProxyModel or depending on what your models are, you can maybe use KConcatenateRowsProxyModel

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Dariusz
            wrote on 16 Mar 2019, 08:13 last edited by
            #5

            Thanks for info!

            Right so I'm in middle of creating models (wow so much fun...) and I wonder... if I take QAbstractTableModel, wack it around so I can add widgets to it, can I then pass that to QProxyModel and have it all work? I take I would also have to extend the QProxyModel to accommodate my widgets from my customTableModel ?

            J 1 Reply Last reply 16 Mar 2019, 10:25
            0
            • D Dariusz
              16 Mar 2019, 08:13

              Thanks for info!

              Right so I'm in middle of creating models (wow so much fun...) and I wonder... if I take QAbstractTableModel, wack it around so I can add widgets to it, can I then pass that to QProxyModel and have it all work? I take I would also have to extend the QProxyModel to accommodate my widgets from my customTableModel ?

              J Offline
              J Offline
              JonB
              wrote on 16 Mar 2019, 10:25 last edited by JonB
              #6

              @Dariusz
              I'm a little lost at your repeated mention of "widgets" when you are asking about "models", QAbstractTableModel & QAbstractProxyModel.

              If you haven't done so already, have a read of the Qt introductory stuff for "model/view", https://doc.qt.io/qt-5/model-view-programming.html & https://doc.qt.io/qt-5/modelview.html. Your models hold only your data, they know nothing about how you display it, so no widgets or GUI stuff. That is the job of your views. Typically for these models you might use https://doc.qt.io/qt-5/qtableview.html as the view, or you can start to roll your own from QAbstractItemView (https://doc.qt.io/qt-5/qabstractitemview.html). It is only at the view side that you start talking about/adding widgets.

              Finally, note that the classes you talk about have Abstract in them. Abstract classes mean that you have to write the code to do the actual work. As opposed to the concrete classes which are derived from them, e.g. https://doc.qt.io/qt-5/qsortfilterproxymodel.html. (Qt docs for each Abstract class mention which pre-supplied Qt concrete classes derive from them.) You may need to start from an abstract class because what you wish to achieve is not provided by the supplied concrete classes, but be aware that you have to do quite a bit of work to correctly concretize them, it's in the docs, but you will have to read up & implement....

              D 1 Reply Last reply 16 Mar 2019, 22:05
              0
              • J JonB
                16 Mar 2019, 10:25

                @Dariusz
                I'm a little lost at your repeated mention of "widgets" when you are asking about "models", QAbstractTableModel & QAbstractProxyModel.

                If you haven't done so already, have a read of the Qt introductory stuff for "model/view", https://doc.qt.io/qt-5/model-view-programming.html & https://doc.qt.io/qt-5/modelview.html. Your models hold only your data, they know nothing about how you display it, so no widgets or GUI stuff. That is the job of your views. Typically for these models you might use https://doc.qt.io/qt-5/qtableview.html as the view, or you can start to roll your own from QAbstractItemView (https://doc.qt.io/qt-5/qabstractitemview.html). It is only at the view side that you start talking about/adding widgets.

                Finally, note that the classes you talk about have Abstract in them. Abstract classes mean that you have to write the code to do the actual work. As opposed to the concrete classes which are derived from them, e.g. https://doc.qt.io/qt-5/qsortfilterproxymodel.html. (Qt docs for each Abstract class mention which pre-supplied Qt concrete classes derive from them.) You may need to start from an abstract class because what you wish to achieve is not provided by the supplied concrete classes, but be aware that you have to do quite a bit of work to correctly concretize them, it's in the docs, but you will have to read up & implement....

                D Offline
                D Offline
                Dariusz
                wrote on 16 Mar 2019, 22:05 last edited by
                #7

                @JonB said in Model view widget with different root item ?:

                @Dariusz
                I'm a little lost at your repeated mention of "widgets" when you are asking about "models", QAbstractTableModel & QAbstractProxyModel.

                I'm actually asking about widgets here, QTableWidget to be precise, but to behave like QTableView where model can be shared between multiple views. I've already started coding it and implementing needed functions for creation/insertions of widgets in to it, but what made me wonder is if I can still pass it to QProxyModel... kinda tricky. Technicly as long as the model provides needed functions for QProxyModel and I do data extraction right from widget based on my types, it should work... "Maybe"... :- )

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 16 Mar 2019, 22:10 last edited by
                  #8

                  QTableWidget is a convenience widget for simple situation. As soon as you are doing custom stuff like you are currently doing, don't think about it.

                  You can have several layers of proxy if you want, e.g. the QSortFilterProxy that filters on top of your "model uniting proxy" that itself is on top of your multiple models.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  D 1 Reply Last reply 16 Mar 2019, 22:35
                  0
                  • S SGaist
                    16 Mar 2019, 22:10

                    QTableWidget is a convenience widget for simple situation. As soon as you are doing custom stuff like you are currently doing, don't think about it.

                    You can have several layers of proxy if you want, e.g. the QSortFilterProxy that filters on top of your "model uniting proxy" that itself is on top of your multiple models.

                    D Offline
                    D Offline
                    Dariusz
                    wrote on 16 Mar 2019, 22:35 last edited by
                    #9

                    @SGaist Woah... I have lots to read! Thanks! Gotta dig into proxier more then.

                    1 Reply Last reply
                    0

                    5/9

                    16 Mar 2019, 08:13

                    • Login

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