Results 1 to 13 of 13

Thread: How to make QAbstractItemModel 's data checkable

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to make QAbstractItemModel 's data checkable

    Quote Originally Posted by DPB1956 View Post
    I’m having the same problem making QAbstractItemModel 's data checkable.
    I can set the checked/unchecked state in data() but I can’t set the checkbox to a checkable state. I added Qt::ItemIsUserCheckable to flags() but this does nothing.
    Does nothing in what way?

    QAbstractItemModel doesn't contain any data, it is an abstract interface that you can implement any way you like. When you create your implementation of the that interface you control how it behaves. If you want a view to allow checking of an item from your model then you need to return Qt::ItemIsUserCheckable amongst the flags() for the item (which should be editable). You will also need to do something sane with Qt::CheckStateRole in the implementation of data() and setData().

    If you want a function like QStandardItem::setCheckable() to apply check-ability on an item-by-item basis then you need to add the method to your implementation and find somewhere to store the check-ability flags against an item in your model implementation. One solution is to use another role on the item to store/retrieve the check-ability attribute (i.e. like QStandardItemModel does) but you could equally use another structure. How you do it is entirely up to you because only you know what the data being presented through the model looks like.

    Whether a view does anything with the checkable state is another question.

  2. The following user says thank you to ChrisW67 for this useful post:

    DPB1956 (23rd August 2011)

  3. #2
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows Symbian S60

    Default Re: How to make QAbstractItemModel 's data checkable

    Thanks for responding. After adding setData() the checkbox is now working properly. I was under the impression that setting Qt::ItemIsUserCheckable to flags() would work the same way as setCheckable(true) in QStandardItemModel where the checkbox could be toggled without setting any additional flags.

    Thanks for your help.

  4. The following user says thank you to DPB1956 for this useful post:

    Anjan@369 (1st April 2013)

Similar Threads

  1. Best way to display lots of data fast
    By New2QT in forum Newbie
    Replies: 4
    Last Post: 16th October 2008, 22:46
  2. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 05:57
  3. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53

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.