Results 1 to 3 of 3

Thread: QTreeView and QStandardItemModel limitations when using custom delegates

  1. #1
    Join Date
    Mar 2014
    Posts
    9
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default QTreeView and QStandardItemModel limitations when using custom delegates

    Untitled.png

    Hi all,

    I have problem using QTreeView with delegates in a QStandardItemModel model. I used the setItemDelegateForColumn method to apply my delegate to the second column of my QTreeView but it is also applied on the "root" rows column which I don't want. It doesn't seem possible to apply a delegate on a specific number of cells.

    I attached a picture to this thread showing my ongoing result. If mya briefly comment it, I would like the <arbiter> row ComboBox delegate to dissapear. What do I have to do in order to get what I want ? Implement a custom Model or a Custom view ?

    Ideally I would like to implement the "Property Editor" of QtCreator but I don't know how to do this.

    Thanks for your help
    Last edited by enter; 4th March 2014 at 20:53.

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

    Default Re: QTreeView and QStandardItemModel limitations when using custom delegates

    It doesn't seem possible to apply a delegate on a specific number of cells.
    The delegate is free to distinguish between cells any way it sees fit. For example, do not paint the top level cells:
    Qt Code:
    1. // something like
    2. void MyDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    3. {
    4. if (!index.isvalid())
    5. return;
    6.  
    7. const QModelIndex leftmostSibling = index.sibling(index.row(), 0);
    8. if (leftmostSibling.parent().isValid()) {
    9. // not on top level of tree
    10. // paint stuff
    11. }
    12. else {
    13. // default behaviour
    14. QStyledItemDelegate::paint(painter, option, index);
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 


    You can look at the source for the "Property Editor" of QtCreator, so there should not be a huge mystery.
    There's also an independent implementation at http://qt-apps.org/content/show.php/...?content=68684 but I cannot vouch for its completeness, robustness etc.

  3. #3
    Join Date
    Mar 2014
    Posts
    9
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView and QStandardItemModel limitations when using custom delegates

    Thanks for the tips ! That did the trick.

    I also had to check parent validity in the createEditor method of my delegate class

Similar Threads

  1. Custom tablemodel and delegates problem.
    By tonnot in forum Qt Programming
    Replies: 2
    Last Post: 9th November 2011, 07:24
  2. QTreeView, Delegates and Persistent Widgets
    By chezifresh in forum Qt Programming
    Replies: 16
    Last Post: 16th December 2009, 09:30
  3. QTreeView - persistentEditor or delegates
    By moti.lahiani in forum Qt Programming
    Replies: 0
    Last Post: 23rd July 2009, 15:19
  4. row height with QTreeView and delegates
    By Philipp in forum Qt Programming
    Replies: 7
    Last Post: 11th November 2008, 10:40
  5. can't do a QTreeView with a QStandardItemModel
    By Nuria in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2006, 00:41

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