Important: Please read the Qt Code of Conduct -

How to connect QStandardItem checkbox to a slot

  • Hello!!

    I have an application with a QTreeView. This QTreeView has QStandardItems and I have put a checkbox in them with the setCheckable() property. How can I connect this checkbox with a slot?

    Thank you very much!

  • Requires Qt >= 5.11

    connect(model,&QAbstractItemModel::dataChanged,[](const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles){
        if(!roles.isEmpty() && !roles.contains(Qt::CheckStateRole))
        for(int i=topLeft.row();i<=bottomRight.row();++i){
            for(int j=topLeft.column();j<=bottomRight.column();++j){
                qDebug() << "CheckBox Changed: Item data" <<  topLeft.model()->index(i,j,topLeft.parent()).data();

  • @VRonin Thank you very much!!! That's that I need!!

Log in to reply