Results 1 to 9 of 9

Thread: Treeview and custom model

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: Treeview and custom model

    Remove DACanTreeModel::index(). It's incorrect and makes the model to not work properly. There should be no need to reimplement it.

    Edit: Sorry, forget what I just said. For some reason I read it as QAbstractTableModel. Some other thread must have confused me. For QAbstractItemModel you naturally need to implement index() since it's pure virtual. But do you really need a QAbstractItemModel? In some other thread your data looked flat to me, so maybe you should consider using QAbstractTableModel which makes things easier for you.
    Last edited by jpn; 15th May 2007 at 13:24.
    J-P Nurmi

  2. #2
    Join Date
    Oct 2006
    Posts
    279
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    6
    Thanked 40 Times in 39 Posts

    Default Re: Treeview and custom model

    At the moment your model is flat and you can access any item with (row, column), thus your createIndex function can be very simple. If you're intending to make a truly hierarchical model, that won't be enough, though and you will have to store more information in the QModelIndex::internalPointer(). For example you could store a pointer to the parent item.
    If you really need a hierarchical model I suggest you take look at the Simple Tree Model Example. Otherwise it will be a lot easier to go with the QAbstractTableModel as jpn suggested.
    Last edited by spud; 15th May 2007 at 13:38. Reason: spelling

  3. #3
    Join Date
    May 2007
    Posts
    301
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    46
    Thanked 3 Times in 3 Posts

    Default Re: Treeview and custom model

    Hi JPN,

    Don't think the data is flat, well, not 2d, as the first column will show message nodes with their corresponding signal nodes. Unless I'm mistaken, QAbstractTableModel doesn't allow this?

    Please see attachment of what I'm trying to do.

    Regards,
    Steve
    Attached Files Attached Files

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: Treeview and custom model

    Quote Originally Posted by steg90 View Post
    Don't think the data is flat, well, not 2d, as the first column will show message nodes with their corresponding signal nodes. Unless I'm mistaken, QAbstractTableModel doesn't allow this?

    Please see attachment of what I'm trying to do.
    Yes, you're right. The model needs to handle parent-child relationships. Well, good luck with implementing a tree model then! Model Test might be handy for checking out the most common mistakes.
    J-P Nurmi

  5. #5
    Join Date
    May 2007
    Posts
    301
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    46
    Thanked 3 Times in 3 Posts

    Default Re: Treeview and custom model

    Thanks JPN,

    I've decided to go for the table model as I don't really need to display the message name and data as the messages are chosen from a previous dialog, this will be the easier option for me as I'm totally confused about the modelIndex and the internalPointer() function?!

    Kind regards,
    Steve

Similar Threads

  1. TreeView custom model
    By steg90 in forum Newbie
    Replies: 1
    Last Post: 9th May 2007, 10:06

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.