Best way to have check box click functionality on in checkbox region of QTreeView?
I have a QTreeView with checkboxes on some items. Right now, my view can toggle the state of the checkbox in the model using the QAbstractItemView::clicked ( const QModelIndex & index ) signal. However, I would like to only toggle the state if the user is actually clicking within the checkbox region of the item, not simply anwhere within the whole item. Is there a reliable way to know where within the item the user is clicking? It seems like fairly standard UI functionality to only have the checkbox toggle when you are clicking within it.
Colby
Re: Best way to have check box click functionality on in checkbox region of QTreeView
Are you using QCheckboxes as index widgets?
How about if you try using user checkable items?
Make sure your model returns Qt::ItemIsUserCheckable flag for indexes you want to be checkable and both data() and setData() handle role Qt::CheckStateRole.
Re: Best way to have check box click functionality on in checkbox region of QTreeView
Thanks! Your solution works. I wasn't aware of the Qt::ItemIsUserCheckable functionality. It does exactly what I need. I already had Qt::CheckStateRole covered in data() and setData(), which made the checkboxes appear, but I was trying to emulate the Qt::ItemIsUserCheckable functionality with my own UI code, which I couldn't get to work as cleanly.
Colby
Re: Best way to have check box click functionality on in checkbox region of QTreeView
Hello,
This disables the complete row.How to disable single item in a row??
i have a QTreeWidgetItem* p, 'p' has about 12 items (12 Columns). i need to disable items in index 5,6 and 8. Other items should not be changed.
Any idea how to do that?
Thanks....