0

Is it possible to have more states for QCheckbox than Qt::Checked and Qt::Unchecked? I have a QTreeWidget 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 Qt::Checked 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->setText(0,text);
    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!

Community
  • 1
  • 1
honiahaka10
  • 772
  • 4
  • 9
  • 29

1 Answers1

3

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.

Arnav Borborah
  • 11,357
  • 8
  • 43
  • 88
  • 1
    Thank you, as I already said in comment of my post: I was searching for "filled qcheckbox" and could not find anything like that, thats exactly what I need. – honiahaka10 Sep 03 '16 at 12:46