Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved table view click will "deselect others" when user clicks pre-selected row?

    General and Desktop
    2
    8
    488
    Loading More Posts
    • 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
      davecotter last edited by

      is there any way to turn that OFF?

      eg: if i have "row selection" turned on

      and i have multiple rows selected
      and i click in a row that is already selected...

      i want it to NOT deselect other selected rows. i want to intervene and do my own thing...

      is there a simple way to override that?

      Pl45m4 1 Reply Last reply Reply Quote 0
      • Pl45m4
        Pl45m4 @davecotter last edited by Pl45m4

        @davecotter

        The MultiSelection mode could work for you, but I guess that's not 100% what you expect.

        https://doc.qt.io/qt-5/qabstractitemview.html#SelectionMode-enum

        Do you have your own, custom TableView already? Then you could easily implement this behavior and trigger it with selectionChanged signal or simply override QTableView::selectionChanged(...)

        https://doc.qt.io/qt-5/qtableview.html#selectionChanged

        Edit:
        I guess intercepting the click works better for you.
        (but then you have to find a solution how to deselect rows again)
        https://doc.qt.io/qt-5/qabstractitemview.html#clicked


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply Reply Quote 1
        • D
          davecotter last edited by

          yes i have a custom tableView.

          no, multiSelection mode doesn't help: it's default behavior is to deselect all the rows you didn't click on.

          overriding selectionChanged() won't work because by that time the selection has already changed, it's too late.

          you suggest intercepting the click, but that method is not marked virtual, so you can't override it.

          Pl45m4 1 Reply Last reply Reply Quote 0
          • Pl45m4
            Pl45m4 @davecotter last edited by Pl45m4

            @davecotter said in table view click will "deselect others" when user clicks pre-selected row?:

            you can't override it

            But since it's a signal, you can react on that :)

            I'm not 100% familiar with the exact order of events (when the selection actually changes), but doing something with QAbstractItemView::mousePressEvent might also work.
            Block the further processing when the selection of the other rows is about to change and replace it with your own, wanted behavior.
            https://doc.qt.io/qt-5/qabstractitemview.html#mousePressEvent

            EDIT:

            I just played around with a standard QTableWidget a bit... Have you tried to press and hold Shift while clicking your selected row? I should not touch the current selection. At least in my test, the selected and clicked row stays selected as well as other items or rows that were selected before...


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply Reply Quote 0
            • D
              davecotter last edited by

              you suggest holding the shift key while selecting, but that's asking the user to change their behavior (change the spec), rather than coding the app to conform to the spec. the spec is that selection doesn't change when you click a row that is already selected (similar to what happens when you do a drag-and-drop). yes it doesn't change on mouse down: good. but it also MUST NOT change on mouse up.

              Pl45m4 1 Reply Last reply Reply Quote 0
              • Pl45m4
                Pl45m4 @davecotter last edited by

                @davecotter said in table view click will "deselect others" when user clicks pre-selected row?:

                you suggest holding the shift key while selecting, but that's asking the user to change their behavior

                No, I was talking about the "final" click onto that row, that is already seleted to "do your own thing" afterwards. The normal selection can be done as usual without holding any key.

                @davecotter said in table view click will "deselect others" when user clicks pre-selected row?:

                ather than coding the app to conform to the spec

                If you change your selection behavior on the app side, you need to find a way how to deselect rows again, which will not work the normal way anymore.

                Then, I would say, the mousePressEvent is the way to go... as long as nobody here got a better idea :)


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                1 Reply Last reply Reply Quote 0
                • D
                  davecotter last edited by

                  i'm not sure i follow your example about the "final click"?
                  can you pseudocode that?

                  the spec is: if you want to "Deselect All", use the Edit menu command, or click on an unselected row (which deselects all other rows), then cmd/ctrl click that row again to deselect it.

                  Pl45m4 1 Reply Last reply Reply Quote 0
                  • Pl45m4
                    Pl45m4 @davecotter last edited by Pl45m4

                    @davecotter said in table view click will "deselect others" when user clicks pre-selected row?:

                    can you pseudocode that?

                    There is no code :) As I said, I was playing around a bit. I used the Shift key while clicking on selected rows and other rows stayed selected. But I dont know how it will impact the rest of your code, if you click while holding Shift (in addition, it's not very intuitive).

                    So I can't deliver you THE optimal solution (and I dont know, if anybody has done something similar before). These were thoughts how I would do it or where I would start :)

                    @davecotter said in table view click will "deselect others" when user clicks pre-selected row?:

                    yes it doesn't change on mouse down: good. but it also MUST NOT change on mouse up

                    The clicked signal gets triggered on mouseReleaseEvent first.


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    1 Reply Last reply Reply Quote 1
                    • First post
                      Last post