[英]Disable a column of a QTreeWidgetItem or remove set CheckBox
I have QTreeWidgetItem
set in a QTreeWidget
with 2 columns.我在
QTreeWidgetItem
设置了QTreeWidget
有 2 列。 Both cells got a CheckBox set by setCheckState(...)
.两个单元格都有一个由
setCheckState(...)
设置的 CheckBox 。
When the user unchecks the CheckBox in my first column I uncheck the second CheckBox in column 2.当用户取消选中第一列中的复选框时,我取消选中第 2 列中的第二个复选框。
Now, I would like to prevent the user to check this second CheckBox again.现在,我想阻止用户再次检查第二个 CheckBox。 Is it possible to remove this CheckBox in column 2 or to disable only this cell?
是否可以删除第 2 列中的此复选框或仅禁用此单元格? So far I have just seen that all the flags work on the complete item and a set CheckBox won't disapear.
到目前为止,我刚刚看到所有标志都适用于完整的项目,并且设置的 CheckBox 不会消失。
Btw.顺便说一句。 The items are not editable and I don't want to use a
QTableWidget
/ -Item
.这些项目不可编辑,我不想使用
QTableWidget
/ -Item
。
The CheckBox will be automatically inserted by Qt when I call setCheckState for the item:当我为项目调用 setCheckState 时,Qt 将自动插入 CheckBox:
QTreeWidgetItem *item = new QTreeWidgetItem(ui.TreeWidget);
item->setCheckState(0, Qt::Checked);
After the new
the item does not own a CheckBox (by Qt default). new
项目不拥有 CheckBox 之后(Qt 默认情况下)。 Calling setCheckState(...)
I automatically insert a CheckBox (here in column 0) with the Qt::CheckState
I want.调用
setCheckState(...)
我会自动插入一个带有我想要的Qt::CheckState
的 CheckBox(这里是第 0 列)。
But after I have done it there's no way to remove the CheckBox - so it seems.但是在我完成之后,没有办法删除 CheckBox - 看起来是这样。
Maybe anyone got a solution how I can get rid of this CheckBox at a later time?也许有人有一个解决方案,我如何在以后摆脱这个 CheckBox? Any help is much appreciated!
非常感谢任何帮助!
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. setCheckState 方法不能设置“无检查状态”,只能设置 Checked、PartiallyChecked 或 Unckecked。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.