Hi,
I'm using QT Creator to develop an small application. I have a QTreeWidget in the UI and I use the following code to populated:
mainhh->setText(0, tr("Main Table"));
//Move the items to the list
lista << tr("Sub-table 1");
lista << tr("Sub-table 2");
lista << tr("Sub-table 3");
//Many more items ........
//Add the list of subtables as a children of Main Table
//Many more parent nodes and childs.......
this->ui->treetables->expandAll(); //Expand the tree
QTreeWidgetItem *mainhh = new QTreeWidgetItem(this->ui->treetables);
mainhh->setText(0, tr("Main Table"));
QStringList lista;
//Move the items to the list
lista << tr("Sub-table 1");
lista << tr("Sub-table 2");
lista << tr("Sub-table 3");
//Many more items ........
//Add the list of subtables as a children of Main Table
new QTreeWidgetItem(mainhh,lista,0);
//Many more parent nodes and childs.......
this->ui->treetables->expandAll(); //Expand the tree
To copy to clipboard, switch view to plain text mode
The code works fine but how can I check/uncheck all the items after I have fulled populated the tree e.g., by clicking a button called "Check/Uncheck all". I guess I need to set some flags and properties to each items with something like:
setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
setCheckState(Qt::Unchecked); //or QT::Checked
setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
setCheckState(Qt::Unchecked); //or QT::Checked
To copy to clipboard, switch view to plain text mode
But.... I don't know how to go through all the items in the tree to set those properties and flags to each item.
Many thanks,
QLands
Bookmarks