Results 1 to 4 of 4

Thread: QTreeView with QStandardItemModel

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

    Default QTreeView with QStandardItemModel

    Hi,

    I'm needing a view which shows hierarchical data, hence a tree. The objects I want rendering in the tree consist of N amount of messages (which have message data) which in turn have N amount of signals where each signal has a signal data field and a unit conversion type. Thus the message will be the parent node for the signal(s). I will have a view which will have four columns, first column will be the messages with the signal nodes, second column the message data, third column signal data and fourth signal unit.

    What I want to know is, as the signal and message data can change every millisecond, I need the tree to reflect this, would the QStandardItemModel be fast enough? There will only ever be a maximum of ten messages in the tree although these can also have upto ten signals each. I guess, deleting all items in the tree and updating again would be very slow, what I've tended to do in my MFC apps is just change the corresponding tree item.

    Any advice is much appreciated,
    Regards,
    Steve

    PS - this is the object structure for messages and signals ( not all the variables in each object are needed for the tree view ):

    Qt Code:
    1. class CSignal
    2. {
    3. public:
    4. char m_name[256];
    5. char m_unit[256];
    6. double m_dmaximum;
    7. double m_dminimum;
    8. double m_dfactor;
    9. double m_doffset;
    10. UINT m_istartbit;
    11. UINT m_ilength;
    12. double m_drealvalue;
    13. long m_lrawvalue;
    14. double m_dbyteorder;
    15. };
    16.  
    17. // Holds a message along with its list of signals
    18. class CMessage
    19. {
    20. public:
    21. char m_name[256]; // message user friendly name
    22. CString m_strId;
    23. CString m_strData; // data for message
    24. CString m_strRawData;
    25. QList<QObject*> m_oSignals;
    26. };
    27. Q_DECLARE_METATYPE(CDADcb::CMessage*)
    28.  
    29. QHash<QString,QObject*> m_oMessages;
    To copy to clipboard, switch view to plain text mode 

    The variable m_oMessages is the hash map that holds the messages and signals.

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

    Default Re: QTreeView with QStandardItemModel

    Yes, the standard model will be fine, although with having such a structure, I'd implement a custom model that uses this structure directly. It'll save you some work...

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

    Default Re: QTreeView with QStandardItemModel

    Thanks for the reply. I'm pretty new to Qt and although I've done custom model for a tableview, was wondering how I'd go about doing one for the treeview?

    Kind regards,
    Steve

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

    Default Re: QTreeView with QStandardItemModel

    Take a look at the simpletreemodel example bundled with Qt.

Similar Threads

  1. can't do a QTreeView with a QStandardItemModel
    By Nuria in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2006, 00:41

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.