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

27th September 2009, 12: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.column() != 0)


if (ui->treeView->model()->data(index, Qt::CheckStateRole) == Qt::Checked)
qDebug() << "Selected";
ui->treeView->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows);
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

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

27th September 2009, 21:36
Thanks caduel

that worked very well :)