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 clicked() not triggering when dragging and selecting a range of data in the table?

QTableView clicked() not triggering when dragging and selecting a range of data in the table?

Scheduled Pinned Locked Moved Solved General and Desktop
qtableviewtableviewtabletable view
7 Posts 3 Posters 1.6k 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.
  • R Offline
    R Offline
    R-P-H
    wrote on 26 Sept 2022, 14:08 last edited by R-P-H
    #1

    Hi,

    I have a slot for QTableView clicked(QModelIndex index). I noticed that if I click and drag a selection in the table (extended selection) the clicked() signal is not emitted? Clicking a single record works fine though.

    J J 2 Replies Last reply 26 Sept 2022, 14:12
    0
    • R R-P-H
      26 Sept 2022, 14:08

      Hi,

      I have a slot for QTableView clicked(QModelIndex index). I noticed that if I click and drag a selection in the table (extended selection) the clicked() signal is not emitted? Clicking a single record works fine though.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 26 Sept 2022, 14:12 last edited by jsulm
      #2

      @R-P-H Mouse click means that mouse button was pressed AND released over same widget. Pressing mouse button down over one widget and releasing it over another isn't a click.
      You can use https://doc.qt.io/qt-6/qabstractitemview.html#pressed

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply 27 Sept 2022, 10:15
      2
      • R R-P-H
        26 Sept 2022, 14:08

        Hi,

        I have a slot for QTableView clicked(QModelIndex index). I noticed that if I click and drag a selection in the table (extended selection) the clicked() signal is not emitted? Clicking a single record works fine though.

        J Offline
        J Offline
        JonB
        wrote on 26 Sept 2022, 14:14 last edited by
        #3

        @R-P-H
        clicked() is for a single cell. selectionChanged() will happen for your drag, or QItemSelectionModel::selectionChanged() on the selectionModel().

        R 1 Reply Last reply 26 Sept 2022, 14:24
        0
        • J JonB
          26 Sept 2022, 14:14

          @R-P-H
          clicked() is for a single cell. selectionChanged() will happen for your drag, or QItemSelectionModel::selectionChanged() on the selectionModel().

          R Offline
          R Offline
          R-P-H
          wrote on 26 Sept 2022, 14:24 last edited by
          #4

          @JonB Any slot that can capture both the click and drag ?

          J 1 Reply Last reply 26 Sept 2022, 14:53
          0
          • R R-P-H
            26 Sept 2022, 14:24

            @JonB Any slot that can capture both the click and drag ?

            J Offline
            J Offline
            JonB
            wrote on 26 Sept 2022, 14:53 last edited by JonB
            #5

            @R-P-H
            No, because as @jsulm wrote you are not clicking. A click is a mouse down and up while on a cell. But you don't do that, do you? You mouse down and then drag-move the mouse while still down without up, don't you? Which is why he gave you a reference to pressed() signal instead. And you can't have one signal for "both the click and drag" even if "click" is "press" because they happen at different times. Or, doubtless you can re-implement drag-selection yourself and do what you want there, but can't believe it's worth the effort or a good idea.

            R 1 Reply Last reply 27 Sept 2022, 10:14
            1
            • J JonB
              26 Sept 2022, 14:53

              @R-P-H
              No, because as @jsulm wrote you are not clicking. A click is a mouse down and up while on a cell. But you don't do that, do you? You mouse down and then drag-move the mouse while still down without up, don't you? Which is why he gave you a reference to pressed() signal instead. And you can't have one signal for "both the click and drag" even if "click" is "press" because they happen at different times. Or, doubtless you can re-implement drag-selection yourself and do what you want there, but can't believe it's worth the effort or a good idea.

              R Offline
              R Offline
              R-P-H
              wrote on 27 Sept 2022, 10:14 last edited by
              #6

              @JonB Thanks, I understand.

              1 Reply Last reply
              0
              • J jsulm
                26 Sept 2022, 14:12

                @R-P-H Mouse click means that mouse button was pressed AND released over same widget. Pressing mouse button down over one widget and releasing it over another isn't a click.
                You can use https://doc.qt.io/qt-6/qabstractitemview.html#pressed

                R Offline
                R Offline
                R-P-H
                wrote on 27 Sept 2022, 10:15 last edited by
                #7

                @jsulm said in QTableView clicked() not triggering when dragging and selecting a range of data in the table?:

                @R-P-H Mouse click means that mouse button was pressed AND released over same widget. Pressing mouse button down over one widget and releasing it over another isn't a click.
                You can use https://doc.qt.io/qt-6/qabstractitemview.html#pressed

                pressed() worked for me. Thanks !

                1 Reply Last reply
                0

                3/7

                26 Sept 2022, 14:14

                • Login

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