PDA

View Full Version : can't do a QTreeView with a QStandardItemModel



Nuria
26th July 2006, 00:38
I'm trying to do a QTreeView but I cannot make childs.

my code to fill in the model is:
void FactoryJob::procesaTrabajo()
{
qDebug() << "procesaTRabajo";
QModelIndex parent = QModelIndex();
m_model->insertRows(0,1,parent);
QModelIndex indexA = m_model->index(0, 0,parent);
m_model->setData(indexA, "hola");

m_model->insertRows(0,1,indexA);
QModelIndex indexB = m_model->index(0, 0, indexA);
m_model->setData(indexB, "jaja");

m_model->insertRows(1,1,parent);
QModelIndex indexC = m_model->index(1, 0,parent);
m_model->setData(indexC, "adios");

update();

}

And my view only show the indexA and indexC without the [+] and if I ask hasChildren(indexA) the answer is false...

What am I doing wrong?

wysota
26th July 2006, 01:51
Maybe you also need to insertColumns() ?

Nuria
26th July 2006, 18:52
no because I do it before. My problem is I don't see the children indexB but I can see the parents indexA and indexC.

Any others idea?

jacek
26th July 2006, 20:32
no because I do it before.
Are you sure you did that with "indexA" as a parent too?

Try:
m_model->insertRows(0,1,indexA);
m_model->insertColumns(0,1,indexA);
QModelIndex indexB = m_model->index(0, 0, indexA);
m_model->setData(indexB, "jaja");

Nuria
27th July 2006, 00:41
thanks. I solve my problem adding the column