pyqt: Trying to understand insertrows for QAbstractDataModel and QTreeView

主宰稳场 提交于 2019-12-05 04:54:25
Andy M

I'll try and give you some tips, I remember that this part did my head in as well when I had to implement it for my application !

So, from what I remember, you have to implement the following virtual methods :

virtual bool insertRows(int Row, int Count, const QModelIndex& rParent);
virtual bool removeRows(int Row, int Count, const QModelIndex& rParent = QModelIndex());

bool SuperModel::insertRows(int Row, int Count, const QModelIndex& rParent)
{
 ...
    // On débute l'insertion des lignes.
    beginInsertRows(rParent, Row, Row + Count -1);
    // ... Perform insertion here, you'll have something like
    pParent->addChild(Row);
    endInsertRows();
}

bool SuperModel::removeRows(int Row, int Count, const QModelIndex& rParent)
{
    ...
    beginRemoveRows(rParent, Row, Row + Count -1);
    // ... Perform removing here, you'll have something like
    pParent->removeChild(Row);
    endRemoveRows();
}

Some more informations : http://doc.qt.io/archives/qt-4.7/qabstractitemmodel.html#insertRows

I hope it will help you a bit... it's not in PyQt but hopefully it will give you some tips...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!