[SOLVED]QTreeView - removing a row
-
I have a simplified version of my code below which gives me 4 top level rows each containing 4 rows. The problem is how to delete the inner rows? Nothing I have tried will remove an "AA" row and some of the options will not remove any "One" rows either. It seems like this should be obvious but no joy!
@ for(int row(0); row < 4; row++)
{
QStandardItem* parent = new QStandardItem("One");
m_model->appendRow(parent);for(int row2(0); row2 < 4; row2++)
{
QStandardItem* item = new QStandardItem("AA");
parent->appendRow(item);
}
}
@ -
@ QModelIndex index = m_view->currentIndex();
if(index.isValid())
{
CMenuTreeRow *current = (CMenuTreeRow *) m_model->itemFromIndex(index);
if(current)
{
int currentRow = current->row();
CMenuTreeRow *parent = (CMenuTreeRow *) current->parent();
if(parent)//we are at top of tree - do not delete!
{
QModelIndex parentIndex = parent->index();m_model->removeRow(currentRow, parentIndex);
}
}
}
@ -
Hi guys,
Don't forget the startDeleteRows() functions!! The view/model might crash otherwise.
greetz -
OK, thanks :-)