PDA

View Full Version : Best way to have check box click functionality on in checkbox region of QTreeView?



cboles
17th April 2006, 00:00
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

jpn
18th April 2006, 14:42
Are you using QCheckboxes as index widgets?
How about if you try using user checkable (http://doc.trolltech.com/qtopia4.1/html/qt.html#ItemFlag-enum) items?

Make sure your model returns Qt::ItemIsUserCheckable flag (http://doc.trolltech.com/4.1/qabstractitemmodel.html#flags) for indexes you want to be checkable and both data() and setData() handle role Qt::CheckStateRole.

cboles
22nd April 2006, 06:47
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

deepal_de
1st April 2011, 04:58
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....