PDA

View Full Version : Tree View - cannot edit check box



GrahamLabdon
1st June 2011, 12:07
Hi
I am developing a tree widget and have created a class for the tree items and a class for the model.
I can add items to the model and have them displayed in the tree view widget.
Each item has a check box and this is displayed, However, I cannot make the check box change value.
I have attached my source and would be grateful if someone could tell me what I ahve done wrong

Thanks

Graham

Santosh Reddy
1st June 2011, 19:35
Each item has a check box and this is displayed, However, I cannot make the check box change value

You need to write the checked status to the model, this should done in setData() method, I have added, it works. check this out.


bool ReportModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
qDebug() << "ReportModel::setData";
if(role == Qt::CheckStateRole)
{
ReportEditorTreeItem* item = getItem(index);
if(index.column() == 0)
item->setIncluded(value.toBool());
}
emit dataChanged(index,index);
return true;
}

6502