#include void info (QTreeWidgetItem * target, QObject * obj); void MainWindow::on_pushButton_clicked() { // info (ui->pushButton); // info (ui->treeWidget); info (NULL, this); } // #include // #include // #include void MainWindow::info (QTreeWidgetItem * target, QObject * obj) { QTreeWidgetItem * top = new QTreeWidgetItem; if (target == NULL) ui->treeWidget->addTopLevelItem (top); else target->addChild (top); QString s = obj->metaObject()->className(); top->setText (0, s); const QMetaObject * cls = obj->metaObject(); QTreeWidgetItem * branch = new QTreeWidgetItem; branch->setText (0, "super-classes"); top->addChild (branch); QTreeWidgetItem * above = branch; const QMetaObject * super = cls->superClass (); while (super != NULL) { QTreeWidgetItem * node = new QTreeWidgetItem; node->setText (0, super->className()); above->addChild (node); super = super->superClass(); above = node; } branch = new QTreeWidgetItem; branch->setText (0, "properties"); top->addChild (branch); int n = cls->propertyCount (); for (int i = 0; i < n; i++) { QMetaProperty p = cls->property (i); // #include "propitem.h" PropItem * node = new PropItem; node->obj = obj; node->prop = p; QVariant value = p.read (obj); QString v = value.isNull() ? "null" : value.toString(); node->setText (0, p.name () + QString (" : ") + p.typeName () + QString (" = ") + v); branch->addChild (node); } branch = new QTreeWidgetItem; branch->setText (0, "methods"); top->addChild (branch); n = cls->methodCount (); for (int i = 0; i < n; i++) { QMetaMethod m = cls->method (i); QTreeWidgetItem * node = new QTreeWidgetItem; node->setText (0, m.signature ()); branch->addChild (node); } const QObjectList & list = obj->children(); foreach (QObject * item , list) info (top, item); } void MainWindow::on_pushButton_2_clicked() { QList list = ui->treeWidget->selectedItems(); foreach (QTreeWidgetItem * t , list) { PropItem * u = dynamic_cast (t); if (u != NULL) { t->setForeground (0, QColor ("lime")); if (u->prop.type () == QVariant::Int) t->setForeground (0, QColor ("orange")); } else t->setForeground (0, QColor ("red")); if (u != NULL) { if (u->prop.type () == QVariant::Int) { QVariant value = ui->spinBox->value(); u->prop.write (u->obj, value); } else if (u->prop.type () == QVariant::Bool) { QVariant value = ui->checkBox->checkState(); u->prop.write (u->obj, value); } else { QVariant value = ui->lineEdit->text(); u->prop.write (u->obj, value); } } } }