qlands
5th March 2010, 09:22
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:
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
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
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
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:
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
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
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