Results 1 to 10 of 10

Thread: custom model: subclass the item or the model, or store the actual data elsewhere?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2011
    Posts
    70
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    43
    Thanked 4 Times in 2 Posts

    Default Re: custom model: subclass the item or the model, or store the actual data elsewhere?

    I have a copy of that book sitting on my desk right now - a great resource! :-) Their model-view chapter is especially good and far superior to anything I saw online, but I get a little hazy on the particulars.

    My tree basically contains five branches, each with its children having a unique type - say, Person, Place, and Thing to follow the earlier example. I intend to display the entire Person branch as a table, which seems like it should be straightforward. QComboBox, for example, makes displaying lists from a tree model very simple by assigning the model with QComboBox::setModel() and choosing my branch with QComboBox::setRootModelIndex(), but I don't see a similar implementation for a proxy model, even though that is what I'm shooting for.

    I see that perhaps I've been thinking about the model concept backwards (tree --> table versus table --> tree). Structurally, though, the tree makes the most sense for my model

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: custom model: subclass the item or the model, or store the actual data elsewhere?

    QTableView::setRootIndex() does for the QTableView what you describe for the QComboBox. Set your tree model on the QTableView and then setRootIndex() to the QModelIndex of the parent of the Person entries.

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

    Phlucious (14th February 2013)

  4. #3
    Join Date
    Jan 2011
    Posts
    70
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    43
    Thanked 4 Times in 2 Posts

    Default Re: custom model: subclass the item or the model, or store the actual data elsewhere?

    Thanks! It hadn't occurred to me that that might be a view-based concept.

    I'll see about rewiring my brain to approach this from a more model-based perspective (sub-classing QAbstractTableModel), rather than the item-based approach (sub-classing QStandardItem) I've been following up to now. Sounds like that'll flex a little more gracefully as I scale up my application.

Similar Threads

  1. Custom Model? Custom View? Custom Delegate?
    By Doug Broadwell in forum Newbie
    Replies: 4
    Last Post: 11th February 2010, 21:23
  2. Replies: 0
    Last Post: 1st February 2010, 12:00
  3. Replies: 1
    Last Post: 3rd June 2009, 20:08
  4. Default Item View classes and returning data from model
    By xerionn in forum Qt Programming
    Replies: 8
    Last Post: 23rd April 2009, 20:50
  5. Custom model item deletion (Qt4.4)
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 22nd May 2008, 15: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.