ru_core
23rd July 2008, 16:11
Hi all!
There is code which helps to build the tree (picturied lower)
#include <QtGui>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QStandardItemModel model(5, 3);
for (int nTopRow = 0; nTopRow < 5; ++nTopRow) {
QModelIndex index = model.index(nTopRow, 0);
model.setData(index, "item" + QString::number(nTopRow + 1));
model.insertRows(0, 4, index);
model.insertColumns(0, 3, index);
for (int nRow = 0; nRow < 4; ++nRow) {
for (int nCol = 0; nCol < 3; ++nCol) {
QString strPos = QString("%1,%2").arg(nRow).arg(nCol);
model.setData(model.index(nRow, nCol, index), strPos);
}
}
}
QTreeView treeView;
treeView.setModel(&model);
treeView.show();
return app.exec();
}
My task is to insert QStandardItems in the child rows and columns.
tried
void QStandardItemModel::setItem ( int row, int column, QStandardItem * item )
but but the model did not change the count of its rows and columns after new rows and colums have been inserted
do you have any ideas?
Thank you
There is code which helps to build the tree (picturied lower)
#include <QtGui>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QStandardItemModel model(5, 3);
for (int nTopRow = 0; nTopRow < 5; ++nTopRow) {
QModelIndex index = model.index(nTopRow, 0);
model.setData(index, "item" + QString::number(nTopRow + 1));
model.insertRows(0, 4, index);
model.insertColumns(0, 3, index);
for (int nRow = 0; nRow < 4; ++nRow) {
for (int nCol = 0; nCol < 3; ++nCol) {
QString strPos = QString("%1,%2").arg(nRow).arg(nCol);
model.setData(model.index(nRow, nCol, index), strPos);
}
}
}
QTreeView treeView;
treeView.setModel(&model);
treeView.show();
return app.exec();
}
My task is to insert QStandardItems in the child rows and columns.
tried
void QStandardItemModel::setItem ( int row, int column, QStandardItem * item )
but but the model did not change the count of its rows and columns after new rows and colums have been inserted
do you have any ideas?
Thank you