Results 1 to 14 of 14

Thread: View using multiple models

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2009
    Posts
    47
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: View using multiple models

    I am building a custom view to duplicate the attached graphic. The user can change the data used for the histogram, and the parameters of the curve in other views, so the views need to be synced. I had hoped to subclass the QAbstractItemView class to take advantage of the automatic notification, but that appears to need the notifications to be funneled through one model. If I built my own view, but kept the models, then I would need to implement the same connections. And I am unsure of all the connections between the model and the view.

    Please note that, although I have simplified this graphic to just one mathematical curve, the plot could have a dozen such curves. And all of them can be updated by the users elsewhere.
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: View using multiple models

    Ok, you have basically two choices. Either implement a proxy model where you use custom roles (Qt::UserRole and up) to return data from the "second" model or make a proxy where your curves will become additional columns in the proxy model (compared to the source model). From what I see you main model has only one column, so curves can occupy subsequent ones.

    One way or the other you will end up with a single model where two source models are represented either by different roles or by different columns.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    johnmauer (16th January 2010)

  4. #3
    Join Date
    Dec 2009
    Posts
    47
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: View using multiple models

    The approach using different columns is excellent; I had forgotten about the extra column parameter. Thanks a lot.

  5. #4
    Join Date
    Aug 2010
    Posts
    1
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: View using multiple models

    Good day. Could you tell me how to add extra columns to the proxy model, mentioned above? I tried insertColumn() in my QSortFilterProxyModel subclass but it didn't work (returned false).
    Or is it a matter of overriding columnCount() and data() to return the data from the second model in a new column?
    Thanks in advance.

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: View using multiple models

    Quote Originally Posted by QtQuery View Post
    Or is it a matter of overriding columnCount() and data() to return the data from the second model in a new column?
    Yes, that's correct - you need to reimplement at least columnCount(), index(), parent() and data() to take extra columns into account.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    QtQuery (31st August 2010)

  8. #6
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default Re: View using multiple models

    Hello,

    i've the same problem, i need to merge 2 tree models into one treeview.
    The first model is a simple QStandardItemModel. The second model is a QDirModel.
    Now i want to display both models into one treeview. So from the posting i think i need an overlay...

    Qt Code:
    1. CustomModel Items
    2. Custom Item 1 (QStandardItemModel)
    3. Custom SubItem 1 (QStandardItemModel)
    4. Custom SubItem 2 (QStandardItemModel)
    5. Custom Item 2 (QStandardItemModel)
    6. Custom SubItem 1 (QStandardItemModel)
    7. Custom SubItem 2 (QStandardItemModel)
    8. DirModel Items
    9. C: (QDirModel)
    10. Qt (QDirModel)
    11. 2010.05 (QDirModel)
    To copy to clipboard, switch view to plain text mode 

    So, i think i need two functions setCustomModel(QAbstractItemModel *pModel); and a function setDirModel(QAbstractItemModel *pModel); for example.
    But how can i handle it that when i click on an item in the QDirModel to display a file content and if i click on an item in the QStandardItemModel to display for example the a string? To simplify this, i want to know how the treeview knows which model must be accessed.

    I've also attached a screenshot of the current situation. In the left (empty) TreeView i will merge the right ones.

    Thanks in advance

    Best Regards
    NoRulez
    Attached Images Attached Images

Similar Threads

  1. QTreeView and multiple models
    By Daher in forum Qt Programming
    Replies: 3
    Last Post: 3rd December 2019, 20:57
  2. QTreeView with multiple models
    By Daher in forum Qt Programming
    Replies: 5
    Last Post: 18th October 2011, 10:53
  3. QSortFilterProxyModel with multiple source models
    By hoshy in forum Qt Programming
    Replies: 1
    Last Post: 26th August 2009, 20:59
  4. Replies: 3
    Last Post: 5th October 2008, 23:41
  5. Proxy models and slection models
    By amunitz in forum The Model-View Framework
    Replies: 1
    Last Post: 23rd September 2008, 14:35

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.