Results 1 to 3 of 3

Thread: QTreeView and CheckBoxes

  1. #1
    Join Date
    Dec 2009
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QTreeView and CheckBoxes

    Hi all, I would like to know if it is possible to have a TreeView widget displaying check boxes only on some nodes. Up to now I tried subclassing QAbstractItemModel in this way:

    Qt Code:
    1. Qt::ItemFlags MyModel::flags ( const QModelIndex & index ) const
    2. {
    3. if (index.isValid())
    4. {
    5. MyNode* node = static_cast<MyNode*>(index.internalPointer());
    6. if (node->needsCheckbox())
    7. return Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
    8. }
    9.  
    10. return Qt::NoItemFlags;
    11. }
    To copy to clipboard, switch view to plain text mode 

    but the only result I got is that all nodes have a checkbox, and the ones that fail the node->needsCheckbox() method looks greyed out.

    Do I need a custom delegate?

    Thanks in advance...

  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 and CheckBoxes

    Make sure you return an empty QVariant for Qt::CheckStateRole for the items you don't want to have checkboxes in the data() method.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    FreeG (9th December 2009)

  4. #3
    Join Date
    Dec 2009
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeView and CheckBoxes [SOLVED]

    My data() implementation was actually wrong... I thought I was returning an empty QVariant, but it was not the case!

    Thank you very much for your help, very appreciated!

Similar Threads

  1. Checkboxes in Treeview do not get refreshed
    By mesch.t in forum Newbie
    Replies: 5
    Last Post: 13th April 2011, 20:53
  2. qtreeview + checkboxes
    By lamera in forum Newbie
    Replies: 9
    Last Post: 6th September 2008, 22:10
  3. Replies: 3
    Last Post: 25th July 2008, 14:30
  4. Checkboxes in QAbstractITemModel
    By Valheru in forum Qt Programming
    Replies: 5
    Last Post: 28th November 2007, 20:23
  5. QTreeView with checkboxes
    By shad in forum Qt Programming
    Replies: 1
    Last Post: 4th May 2006, 13:29

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.