Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableView Getting Selected Rows According To Selection Order
Qt 6.11 is out! See what's new in the release blog

QTableView Getting Selected Rows According To Selection Order

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DzCode
    wrote on last edited by
    #1

    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?

    JonBJ 1 Reply Last reply
    1
    • D DzCode

      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?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @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.

      D 1 Reply Last reply
      2
      • JonBJ JonB

        @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.

        D Offline
        D Offline
        DzCode
        wrote on last edited by
        #3

        @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.

        JonBJ 1 Reply Last reply
        0
        • D DzCode

          @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.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @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!

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved