honiahaka10 honiahaka10 - 1 year ago 100
C++ Question

QCheckbox: more states than checked and unchecked

Is it possible to have more states for

I have a
and if an Item is checked I want the parent to show a filled checkbox (some state like "Child checked") and the children should then have a state like "parent checked". If latter would be too complex to achieve I think the normal
would also work fine. But how to achieve the first? Here is my code how I am currently adding items with checkboxes:

QTreeWidgetItem* Options::folderMonitoringCreateTreeCheckbox(QDir *dir, bool state, QTreeWidget *parent)
QString text = dir->absolutePath().section('/', -1, -1, QString::SectionSkipEmpty);

QTreeWidgetItem *newItem = new QTreeWidgetItem(parent);
newItem->setFlags(newItem->flags() | Qt::ItemIsUserCheckable);
newItem->setCheckState(0, Qt::Unchecked);
newItem->setToolTip(0, dir->absolutePath());
return newItem;

Here is a Screenshot for what I want to achieve (screenshot taken from MediaMonkey):
enter image description here

Thank you!

Answer Source

I think you are looking for Qt::PartiallyChecked, the description of it says:

The item is partially checked. Items in hierarchical models may be partially checked if some, but not all, of their children are checked.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download