Results 1 to 2 of 2

Thread: QAbstractItemView and tri state check boxes

  1. #1
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default QAbstractItemView and tri state check boxes

    Hello

    I have a model/view that allowed me to display a check box for each item in my tree and allowed the user to check or uncheck the item.

    What I want, however, is that if an item has subitems and these are not all checked then the parent should be partially checked, if they are all checked the parent should be checked and if none are checked then the parent should be unchecked. This should of course be applied to the whole tree.

    I am struggling to implement this and would be grateful if anyone has any suggestions on how I can achieve this

    Thanks

    Graham

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QAbstractItemView and tri state check boxes

    I would assume you are implementing a custom model to do so. In your model's data() method, when view requests for parent's checked status, you need to iterate through all the children, establish the checked status of the parent, and then return to it the view. You could call the data() method recursively for all the children of that parent

    If your tree has a scope of growing larger enough for the iterations to slow down the GUI, then consider storing the pre-calculated checked status in the model data, so as to avoid the iteration on demand.

Similar Threads

  1. Qt tree widget with check boxes iteration
    By denton17 in forum Newbie
    Replies: 1
    Last Post: 9th November 2010, 14:24
  2. Accessing check state of CheckBox in QTableWidget
    By lnxusr in forum Qt Programming
    Replies: 6
    Last Post: 22nd November 2009, 01:13
  3. how to check button state such as "hover"?
    By billconan in forum Qt Programming
    Replies: 2
    Last Post: 12th November 2009, 01:45
  4. Help: How to save Check box state
    By Garibalde in forum Qt Programming
    Replies: 4
    Last Post: 1st July 2009, 20:24
  5. List withembedded check boxes
    By bruccutler in forum Newbie
    Replies: 3
    Last Post: 7th March 2007, 18:17

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.