Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Grid View with 2 models
Forum Updated to NodeBB v4.3 + New Features

Grid View with 2 models

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 320 Views 2 Watching
  • 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.
  • E Offline
    E Offline
    ECEC
    wrote on last edited by
    #1

    I have a Grid View that needs to display 2 different delegates (with different roles), both representing different C++ objects, A and B. A and B do have some common methods, so I was thinking I could subclass them from the same base class and have a QList<Base*> in a single model, combining both object types. I could then do a dynamic_cast in data() to get the subclassed object, and return the correct role, etc.

    Alternatively, is there a way to display data from 2 different models in a single GridView? Although there is some common functionality between A and B that may justify inheritance, there is no interplay between the 2, and combining them into a single model would only be for the sake of displaying them in a single view. Could I achieve something like this with Loaders?

    sierdzioS 1 Reply Last reply
    0
    • E ECEC

      I have a Grid View that needs to display 2 different delegates (with different roles), both representing different C++ objects, A and B. A and B do have some common methods, so I was thinking I could subclass them from the same base class and have a QList<Base*> in a single model, combining both object types. I could then do a dynamic_cast in data() to get the subclassed object, and return the correct role, etc.

      Alternatively, is there a way to display data from 2 different models in a single GridView? Although there is some common functionality between A and B that may justify inheritance, there is no interplay between the 2, and combining them into a single model would only be for the sake of displaying them in a single view. Could I achieve something like this with Loaders?

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @ECEC both your solutions are OK.

      If you want to use something more automated, you can use QConcatenateTablesProxyModel.

      (Z(:^

      E 1 Reply Last reply
      0
      • jeremy_kJ Offline
        jeremy_kJ Offline
        jeremy_k
        wrote on last edited by
        #3

        I don't understand the question. It appears to be conflating delegates (visual representation) with models or data within a model. This is a common in my experience, including with widgets users that are accustomed to usable default delegates. How does 2 different delegates (via DelegateChooser or a homegrown implementation) for one model map to two models with one delegate?

        Code will likely make the question easier to understand. Pseudocode or a toy program is fine.

        Asking a question about code? http://eel.is/iso-c++/testcase/

        1 Reply Last reply
        2
        • sierdzioS sierdzio

          @ECEC both your solutions are OK.

          If you want to use something more automated, you can use QConcatenateTablesProxyModel.

          E Offline
          E Offline
          ECEC
          wrote on last edited by
          #4

          @sierdzio

          Perhaps an even better way would be to maintain 2 separate QLists for A and B within the same model and use their sizes and the QModelIndex in data() to retrieve the correct object. That way I'm not trying to force polymorphism where it doesn't belong and don't have to mess around with Loaders. Which of these 3 options do you think is best?

          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