#include <QApplication>
#include <QStandardItemModel>
#include <QTreeView>
int main(int argc, char *argv[])
{
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 3; ++j) {
item0->setData(100 + j, Qt::UserRole);
parentItem->appendRow(QList<QStandardItem*>() << item0 << item1);
parentItem = item0;
}
}
QModelIndexList matches = model.match(
model.index(0,0),
Qt::UserRole,
-1,
Qt::MatchRecursive);
view.setModel(&model);
view.show();
view.expandAll();
return a.exec();
}
#include <QApplication>
#include <QStandardItemModel>
#include <QTreeView>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QStandardItemModel model;
for (int i = 0; i < 4; ++i) {
QStandardItem *parentItem = model.invisibleRootItem();
for (int j = 0; j < 3; ++j) {
QStandardItem *item0 = new QStandardItem(QString("item %0").arg(j));
item0->setData(100 + j, Qt::UserRole);
QStandardItem *item1 = new QStandardItem(QString::number(100 + j));
parentItem->appendRow(QList<QStandardItem*>() << item0 << item1);
parentItem = item0;
}
}
QModelIndexList matches = model.match(
model.index(0,0),
Qt::UserRole,
QVariant(102),
-1,
Qt::MatchRecursive);
QTreeView view;
view.setModel(&model);
view.show();
view.expandAll();
foreach (const QModelIndex &match, matches)
view.selectionModel()->select(match, QItemSelectionModel::Select);
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks