If you do this:
void ModelTestModel::clicked( const QModelIndex& index )
{
if( index.column() == 0 ){
ModelTestModelItem *item = static_cast< ModelTestModelItem* >( index.internalPointer() );
if( item->checkState() == Qt::Checked )
item->setCheckState( Qt::Unchecked );
else
item->setCheckState( Qt::Checked );
_parent->update( index );
}
}
void ModelTestModel::clicked( const QModelIndex& index )
{
if( index.column() == 0 ){
ModelTestModelItem *item = static_cast< ModelTestModelItem* >( index.internalPointer() );
if( item->checkState() == Qt::Checked )
item->setCheckState( Qt::Unchecked );
else
item->setCheckState( Qt::Checked );
_parent->update( index );
}
}
To copy to clipboard, switch view to plain text mode
then no wonder a click on the whole area makes the item checked. There is no need for such things. The checkable functionality is provided out of the box by the framework. For you it doesn't work, because you didn't implement setData(). If you do and handle changing the Qt::CheckStateRole, it will work as expected.
Bookmarks