Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED] TableView remove all selected items
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] TableView remove all selected items

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 1.8k Views 1 Watching
  • 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.
  • L Offline
    L Offline
    levelxxl
    wrote on last edited by
    #1

    Hi,

    I can't figure out how to remove all selected items of a TableView, when using SelectionMode.ExtendedSelection.

    There is a forEach function in the Selection, but this only iterates over the selection from the begining. The problem is, when doing

    @tableView.selection.forEach( function(rowIndex) { model.remove(rowIndex) } )@

    the first item gets removed, and all following rowIndex values are wrong.

    Has someone a simple solution to this?

    Thanks

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You would need to start from the last selection element and go back to the first

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • L Offline
        L Offline
        levelxxl
        wrote on last edited by
        #3

        I know, but what I don't know is how to sort the selection.

        Is there a way to get the range of the selection as an array?

        The problem is, that when you use SelectionMode.ExtendedSelection, you can select random items. They don't have to be consecutive.

        Thanks

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Are you sure that even if randomly selected, the order of the index returned by selection is the same ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • L Offline
            L Offline
            levelxxl
            wrote on last edited by
            #5

            I have found a solution. You have to use the private __ranges array of the selection object.

            Here is my solution:

            @
            function removeSelectedRows() {
            for (var i = selection.__ranges.length - 1 ; i >= 0 ; -- i) {
            var index = selection.__ranges[i][0];
            var count = 1 + selection.__ranges[i][1] - selection.__ranges[i][0];
            model.remove(index, count)
            }
            selection.clear()
            }
            @

            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