PDA

View Full Version : getting the checkbox value instantly from treeview model



yazwas
27th September 2009, 13:36
Hello All,

I have a standard treeview model that contains checkboxes

I'm trying to get the current status of the checkbox when a user clicks on an item, this click could either be on that element, or on the checkbox (selecting or deselecting)

my problem is that its always giving me the previous status, not the current one, this is my code, and please see if you can help me figure how to solve this :)

I've tried connecting the below slot to the clicked(), activated(), and pressed() signal, and its always the same behavior



void myclass::treeViewClicked(QModelIndex index)
{
if(!index.isValid())
return;

if(index.column() != 0)
return;

ui->treeView->update(index);

if (ui->treeView->model()->data(index, Qt::CheckStateRole) == Qt::Checked)
{
qDebug() << "Selected";
ui->treeView->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows);
//ui->treeView
}
else
{
qDebug() << "NOTTTT Selected";
ui->treeView->selectionModel()->select(index, QItemSelectionModel::Deselect | QItemSelectionModel::Rows);
}
}


even if i click on the checkbox, and select it, it will only show me the previous stat, not the current one

Thank you very much

caduel
27th September 2009, 14:21
why don't you connect to dataChanged() instead?

yazwas
27th September 2009, 22:36
Thanks caduel

that worked very well :)