Results 1 to 4 of 4

Thread: MyCustomStandardItem and hidden data...

  1. #1
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default MyCustomStandardItem and hidden data...

    Hi,
    I'm trying to implement MyCustomStandardItem (inherited from QStandardItem) which has to contain some standard data (i.e. QString, QIcon, etc.) to visualize in a tree view and a list of events associated to the item (QList<Event>, where --> typedef QPair<QDataTime, int> Event) to not visualize in the same tree view...
    Now...I want to visualize the list of events associated to each item through a tootip but I have some problem to retrieve the item events list starting from the item index...I try this solution:
    MyCustomStandardItem* item = static_cast<MyCustomStandardItem*>(itemIndex.inter nalPointer());

    item != NULL, but it crash just after a call an item member function.

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanked 97 Times in 94 Posts

    Default Re: MyCustomStandardItem and hidden data...

    That is because QModelIndex::internalPointer() "[r]eturns a void * pointer used by the model to associate the index with the internal data structure" and there is no way to tell what that internal structure is; in my opinion you should not be using this function. I suspect QStandardItemModel::itemFromIndex() might be what you are looking for.

  3. #3
    Join Date
    Mar 2011
    Location
    Denmark
    Posts
    74
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    7
    Thanked 10 Times in 9 Posts

    Default Re: MyCustomStandardItem and hidden data...

    Instead of creating MyCustomStandardItem I would recommend you use QStandardItem's built in mechanisms for custom data.
    Qt Code:
    1. QStandardItem::setData ( const QVariant & value, int role = Qt::UserRole + 1 )
    To copy to clipboard, switch view to plain text mode 

    The data can then be retrieved with
    Qt Code:
    1. QVariant QStandardItem::data ( int role = Qt::UserRole + 1 )
    To copy to clipboard, switch view to plain text mode 

    To draw the items properly in your widget create a custom QItemDelegate or QStyledItemDelegate

    You also mention you are using a tree view. Consider QTreeWidget then you can use QTreeWidgetItemIterator to iterate over all of the items and extract data from them.

  4. #4
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: MyCustomStandardItem and hidden data...

    Quote Originally Posted by Berryblue031 View Post
    Instead of creating MyCustomStandardItem I would recommend you use QStandardItem's built in mechanisms for custom data.
    Qt Code:
    1. QStandardItem::setData ( const QVariant & value, int role = Qt::UserRole + 1 )
    To copy to clipboard, switch view to plain text mode 

    The data can then be retrieved with
    Qt Code:
    1. QVariant QStandardItem::data ( int role = Qt::UserRole + 1 )
    To copy to clipboard, switch view to plain text mode 

    To draw the items properly in your widget create a custom QItemDelegate or QStyledItemDelegate
    Thanks...it's the solution that I chose!

Similar Threads

  1. Replies: 6
    Last Post: 19th September 2016, 12:44
  2. hidden a QTreeWidgetItem
    By mattia in forum Newbie
    Replies: 6
    Last Post: 19th February 2014, 15:04
  3. The delegated widgets become hidden
    By fulbay in forum Qt Programming
    Replies: 4
    Last Post: 20th December 2010, 13:53
  4. Replies: 2
    Last Post: 21st October 2009, 09:13
  5. Hidden field in QTreeView
    By YuriyRusinov in forum Qt Programming
    Replies: 4
    Last Post: 30th June 2006, 13:00

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.