[SOLVED]Checked and disabled
I got a tableview and in one of the columns there are a chk box.
When the user "checks " this box I would like to set the chkbox ->setEnabled(false).
I have tried but no solution for the moment.
If anyone know how or just give a little hint I would be happy.
If you gave us a little more details we would be happy, too :)
Right now, as I do not know anything about your code/ your attempts, I'll just give a vague hint that might help: use QCheckBox::stateChanged() signal. Connect a slot to it and put your disabling code there.
Are you looking for QAbstractItemModel::flags()? Especially the enabled flag?
Here is some code
I Save the rows in a QVector and when the user peresses a button this code executes
for (int i = 0; i < selectedToAck.size(); ++i)
row = selectedToAck.at(i); //Rownumber
index = model->indexFromItem(model->item(row,4));//Get the columndatat
model->setData(index,"No",Qt::DisplayRole); //Changes the text in the column
//Changes the color of the items
for (int j = 0;j < colCount;j++)
model->setData(model->index(index.row(),j), grey, Qt::ForegroundRole);
//Here is the place where I want to set the item enabled == false
if (j == colCount-1)
This is not all of the code in the method but it's the part that belongs to my problem
What model do you use?
It depends on the model how you can control the enabled flag. If you use [[doc:QStandardItemModel]], you can use QStandardItem::setFlags(), but if you use another type of model, it depends.
I use QStandardItem model
So, does using setFlags() work for you?
Solution in a simple way
@QStandardItem *itm = model->itemFromIndex(model->index(index.row(),j));