View Full Version : what is QComboBox::rootModelIndex?
scarleton
3rd September 2010, 02:46
What is QComboBox::rootModelIndex? I searched the web and cannot find anything, I even searched through the Qt source and only found one reference to it in the qfiledialog.cpp, but it makes little sense. Can anyone enlighten me?
Lykurg
3rd September 2010, 07:26
You need it when working with a tree model. Compare:
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QStandardItemModel model;
QStandardItem *parentItem = model.invisibleRootItem();
for (int i = 0; i < 5; ++i)
{
QStandardItem *item = new QStandardItem(QString("Root %1").arg(i));
for (int j = 0; j < 5; ++j)
{
QStandardItem *itemSub = new QStandardItem(QString("%1:%2").arg(i).arg(j));
item->appendRow(itemSub);
}
parentItem->appendRow(item);
}
QComboBox b;
b.setModel(&model);
b.show();
QComboBox b2;
b2.setModel(&model);
b2.setRootModelIndex(model.index(1,0));
b2.show();
return app.exec();
}
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.