// create a simple model QStandardItemModel* model = new QStandardItemModel; // create some items and set their check state QStandardItem* item1 = new QStandardItem("Item 1"); QStandardItem* item2 = new QStandardItem("Item 2"); // set item1 to checked and item2 to partially-checked item1->setCheckState(Qt::Checked); item2->setCheckState(Qt::PartiallyChecked); // add items to the model model->appendRow(item1); model->appendRow(item2);
QStandardItem* item = model->item(index); if (item->checkState() == Qt::Checked) { // do something if the item is checked }
// create an item QStandardItem* item = new QStandardItem("My Item"); // connect the item to a slot connect(item, &QStandardItem::stateChanged, this, &MyClass::onItemChanged);These examples illustrate how to use the QStandardItem setCheckState method and other related functions. This package library is part of the Qt framework.