Reputation: 31
I have QTreeWidgetItem
set in a QTreeWidget
with 2 columns. Both cells got a CheckBox set by setCheckState(...)
.
When the user unchecks the CheckBox in my first column I uncheck the second CheckBox in column 2.
Now, I would like to prevent the user to check this second CheckBox again. Is it possible to remove this CheckBox in column 2 or to disable only this cell? So far I have just seen that all the flags work on the complete item and a set CheckBox won't disapear.
Btw. The items are not editable and I don't want to use a QTableWidget
/-Item
.
The CheckBox will be automatically inserted by Qt when I call setCheckState for the item:
QTreeWidgetItem *item = new QTreeWidgetItem(ui.TreeWidget);
item->setCheckState(0, Qt::Checked);
After the new
the item does not own a CheckBox (by Qt default). Calling setCheckState(...)
I automatically insert a CheckBox (here in column 0) with the Qt::CheckState
I want.
But after I have done it there's no way to remove the CheckBox - so it seems.
Maybe anyone got a solution how I can get rid of this CheckBox at a later time? Any help is much appreciated!
Upvotes: 3
Views: 4793
Reputation: 144
This will do it:
item->setData(0, Qt::CheckStateRole, QVariant()); //No checkbox at all (what you wanted)
any of these others will show the checkbox space
item->setData(0, Qt::CheckStateRole, Qt::Unchecked); //Unchecked checkbox
item->setData(0, Qt::CheckStateRole, Qt::Checked); //Checked checkbox
item->setData(0, Qt::CheckStateRole, Qt::PartiallyChecked); //Partially checked checkbox (gray)
The setCheckState method can not set 'no check state', only Checked, PartiallyChecked or Unckecked.
Upvotes: 9