Results 1 to 2 of 2

Thread: QTreeView with custom type

  1. #1
    Join Date
    Jul 2010
    Posts
    63
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QTreeView with custom type

    i am using the QTreeView with my custom model, and i need to know when the user triggers edit on the view, so i could send the data.
    the problem is that QTreeView seems to send Qt::displayRole for both display and edit.
    this is rather problematic, since i am also using some custom data types - i want to send a QString for displayRole and the real data for editRole (to send to my custom delegate)

    is there a workaround this ? i'd prefer not to write an entire view just for this tiny detail...

  2. #2
    Join Date
    Jul 2010
    Posts
    63
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeView with custom type

    so i've been sniffing around..
    i found my solution, but a part of it is showing a combo box at all times by reimplementing paint event in my delegate:
    Qt Code:
    1. void polly::RootDelegate::paint(QPainter *painter,
    2. const QStyleOptionViewItem &option,
    3. const QModelIndex &index) const
    4. {
    5. if ( index.data().canConvert<ComboBoxData>() )
    6. {
    7. polly::ComboBoxData d = index.data().value<polly::ComboBoxData>();
    8. box.currentText = d._items.at( d._selected ) ;
    9. box.rect = option.rect;
    10. box.editable = true;
    11. box.state = QStyle::State_Active & QStyle::State_Enabled;
    12.  
    13. QApplication::style()->drawComplexControl(QStyle::CC_ComboBox,
    14. &box, painter);
    15. } else
    16. QStyledItemDelegate::paint(painter, option, index);
    17. }
    To copy to clipboard, switch view to plain text mode 

    problem now is that the "fake" combo box always turns out gray (disabled) and without text.. what did i do wrong?

Similar Threads

  1. how to set custom type data to a QTreeWidgetItem?
    By qlands in forum Qt Programming
    Replies: 2
    Last Post: 4th July 2011, 17:28
  2. how to use custom type items in QTreeWidget?
    By jackal in forum Qt Programming
    Replies: 2
    Last Post: 4th March 2011, 14:05
  3. QVariant custom type.
    By hickscorp in forum Qt Programming
    Replies: 0
    Last Post: 3rd May 2010, 15:23
  4. Using QVariant with custom data type
    By QAlex in forum Qt Programming
    Replies: 3
    Last Post: 4th December 2009, 13:04
  5. Replies: 8
    Last Post: 14th March 2008, 16:10

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.