Results 1 to 6 of 6

Thread: QItemDelegate and QCheckBox

  1. #1
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Arrow QItemDelegate and QCheckBox

    Hello all,

    I'm attempting to implement a checkbox delegate in my tree view, and I'm running into two problems:

    1. The checkbox only appears when I attempt to "edit" a given cell. I'd rather it appear at all times.

    2. When the checkbox does appear, it "overlays" the existing text, making it difficult to read. See the pictures below.

    I'd appreciate any input on the above two problems. I can provide some code, but I suspect I'm having more of a concept problem than a code problem. Thanks!
    Attached Images Attached Images
    Life without passion is death in disguise

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QItemDelegate and QCheckBox

    You should make the items checkable instead of providing a combo box as an editor.

    If you're using QTreeView + model:


    If you're using QTreeWidget:
    Qt Code:
    1. item->setFlags(item->flags() | Qt::ItemIsUserCheckable); // make checkable
    2. item->setCheckState(Qt::Unchecked); // initialize check state to something valid
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QItemDelegate and QCheckBox

    Ok, that works better visually... now how would I go about enabling the user to actually check the boxes? At the moment, I cannot check anything. Should I be listening on setData()? If so, which role should I be on the lookout for?
    Last edited by KShots; 27th July 2007 at 17:30.
    Life without passion is death in disguise

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QItemDelegate and QCheckBox

    Quote Originally Posted by KShots View Post
    Should I be listening on setData()? If so, which role should I be on the lookout for?
    Yes, go for setData() and exactly the same role, Qt::CheckStateRole that is.
    J-P Nurmi

  5. The following 2 users say thank you to jpn for this useful post:

    jml (31st July 2007), KShots (28th July 2007)

  6. #5
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Smile Re: QItemDelegate and QCheckBox

    Thanks, that's exactly the behavior I was looking for
    Life without passion is death in disguise

  7. #6
    Join Date
    Jun 2008
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11
    Wiki edits
    1

    Default Re: QItemDelegate and QCheckBox

    What if it were a QComboBox instead of a QCheckBox (or a custom widget for that matter). How would you display that in a persistent state? (QAbstractItemView allows for openPersistentEditor but that seems pretty cumbersome)

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.