QCheckbox:状态多于选中和未选中
QCheckbox: more states than checked and unchecked
QCheckbox
的状态是否可能比 Qt::Checked
和 Qt::Unchecked
的状态更多?
我有一个 QTreeWidget
,如果一个项目被选中,我希望 parent 显示一个已填充的复选框(某些状态如“Child 已选中”),然后 children 应该有像“parent checked”这样的状态。如果后者太复杂而无法实现,我认为正常的 Qt::Checked
也可以正常工作。但是如何实现第一呢?这是我的代码,我目前如何添加带有复选框的项目:
QTreeWidgetItem* Options::folderMonitoringCreateTreeCheckbox(QDir *dir, bool state, QTreeWidget *parent)
{
QString text = dir->absolutePath().section('/', -1, -1, QString::SectionSkipEmpty);
QTreeWidgetItem *newItem = new QTreeWidgetItem(parent);
newItem->setText(0,text);
newItem->setFlags(newItem->flags() | Qt::ItemIsUserCheckable);
newItem->setCheckState(0, Qt::Unchecked);
newItem->setToolTip(0, dir->absolutePath());
return newItem;
}
这是我想要实现的截图(截图来自 MediaMonkey):
谢谢!
我认为您正在寻找 Qt::PartiallyChecked
,它的描述是:
The item is partially checked. Items in hierarchical models may be partially checked if some, but not all, of their children are checked.
QCheckbox
的状态是否可能比 Qt::Checked
和 Qt::Unchecked
的状态更多?
我有一个 QTreeWidget
,如果一个项目被选中,我希望 parent 显示一个已填充的复选框(某些状态如“Child 已选中”),然后 children 应该有像“parent checked”这样的状态。如果后者太复杂而无法实现,我认为正常的 Qt::Checked
也可以正常工作。但是如何实现第一呢?这是我的代码,我目前如何添加带有复选框的项目:
QTreeWidgetItem* Options::folderMonitoringCreateTreeCheckbox(QDir *dir, bool state, QTreeWidget *parent)
{
QString text = dir->absolutePath().section('/', -1, -1, QString::SectionSkipEmpty);
QTreeWidgetItem *newItem = new QTreeWidgetItem(parent);
newItem->setText(0,text);
newItem->setFlags(newItem->flags() | Qt::ItemIsUserCheckable);
newItem->setCheckState(0, Qt::Unchecked);
newItem->setToolTip(0, dir->absolutePath());
return newItem;
}
这是我想要实现的截图(截图来自 MediaMonkey):
谢谢!
我认为您正在寻找 Qt::PartiallyChecked
,它的描述是:
The item is partially checked. Items in hierarchical models may be partially checked if some, but not all, of their children are checked.