Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

QTableView Getting Selected Rows According To Selection Order



  • Hi all,

    I have a question. I am using selectedrows method of the selection model of the QTableView.

    However, selectedrows() does not return the selected row indexes in order.

    For example, when I do multiselection with mousepress, at first I am selecting row 5, then row 4,3 and 2. However the method returns indexes like 2,3,4,5. I have to get the rows in 5,4,3,2.

    I tried to use selectedindexes metod too, but I am getting an error like "Asert p in qsortfilterproxymodel.cpp in line 190". (Maybe there is a mapping problem in my custom model I do not know).

    Is there anyone knowing the solution?



  • @DzCode
    If by "selected row indexes in order" you mean "the order I actually did the selection clicks" then I'm pretty sure Qt infrastructure will not have recorded that --- why should it? If you really want that you'll have to write your own code to record the order. But that would be unusual --- I cannot think of an application which does so, the user can select-click in any order, all that matters is which rows end up selected.

    I tried to use selectedindexes metod too, but I am getting an error like "Asert p in qsortfilterproxymodel.cpp in line 190". (Maybe there is a mapping problem in my custom model I do not know).

    That will be some error in your own code.



  • @JonB

    Thanks

    So I implemented my custom ordering now as you suggested.

    It would be good if Qt did this recording but no matter. It takes only 5 mins.



  • @DzCode
    Like I said, Qt probably doesn't bother because I don't think any application other than yours cares or acts in click-order!


Log in to reply