I have a QTableView
and a QStandardItemModel
. Is there have a column can contain checkboxes that are user editable without using delegates or using the abstract model classes? It is not that I can't do it, I just want to minimize the code, I would find it overkill for simple check boxes.
By using model.setData(index, Qt::Unchecked,Qt::CheckStateRole)
this creates the checkbox but it is not user editable (text beside checkbox is).
I used modelTX.setData(index, FALSE)
but this creates a combo box containing True and False.
I'll try setItemData
.
pls, check if the following example would work for you:
QStandardItemModel* tableModel = new QStandardItemModel();
// create text item
tableModel->setItem(0, 0, new QStandardItem("text item"));
// create check box item
QStandardItem* item0 = new QStandardItem(true);
item0->setCheckable(true);
item0->setCheckState(Qt::Checked);
item0->setText("some text");
tableModel->setItem(0, 1, item0);
// set model
ui->tableView->setModel(tableModel);
hope this helps, regards
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With