Move qtreeview rows

  • Hello,

    I have a qtreeview with a qstandarditemmodel..

    I would move a row with all subentries to a new position.

    I tried:
    @ moveRow( customerItem->parent()->index(), customerItem->row(),
    _customerGroupsToItems[groupId]->index(), 0);@

    And now, i readed in the documentation auf moveRows:
    @The base class implementation does nothing and returns false.@

    How can i solve my issue?

  • Lifetime Qt Champion


    This is because QStandardItemModel doesn't know anything about your underlying data so it can't move things around for you.

    You have to implement moveRows for your model if you want to use moveRow.

    Hope it helps

  • Hi,
    I had the same problem moving a row within a flat QStandardItemModel. It took some figuring out to get the move operation working properly with eg. QML ListView. I ended up doing:

    @void MyModel::move(int from, int to, int)
    ... //range checking etc.

    int toSignal = to;
    if(from < to){
        toSignal += 1;
    if(!beginMoveRows(QModelIndex(), from, from, QModelIndex(), toSignal)){
    QStandardItem* fromItem = takeItem(from);
    insertRow(to, fromItem);


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.