Nominate our 2022 Qt Champions!

Which models support moving of rows/columns

  • Hello!

    When I look at the documentation,
    I see a statement "On models that support this, ..." and I am wondering which models do support moving?

    Or how can I subclass a model to support moving rows?

    There is no example in the distribution, at least I (say: grep) did not find moveRow in any.

  • Lifetime Qt Champion


    AFAIK there's currently none implementing it.

    As for subclassing, just reimplement the corresponding method and modify your data structure following that. There's not really much more than that.

    Do you have a specific use case ?

  • Well, I did it home grown in some QTreeView with a QStandardItemModel simple by recursivly collecting all expanded child items of that part which I want to move, the remove the rows, insert them and restore the expand-status.

    But since home grown code usually has more errors than some library I was wondering if there is some model, some example supporting this already.

    In addition: moveRow is not virtual, just moveRows is. This is a little bit confusing.

  • Lifetime Qt Champion

    it's because moveRow is just a special case of calling moveRows for one row.

    Anyway, there's something not clear, your talking once about moveColumn then moveRow, which one is it ?

  • Oops, moveRow. And as I said, I have a working implementation. I am just asking.

Log in to reply