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. Is it possible for a QTableView to accept a drop in the empty area below its last row?
Forum Updated to NodeBB v4.3 + New Features

Is it possible for a QTableView to accept a drop in the empty area below its last row?

Scheduled Pinned Locked Moved Solved General and Desktop
qtableviewdrag and drop
7 Posts 2 Posters 4.4k 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.
  • Guy GizmoG Offline
    Guy GizmoG Offline
    Guy Gizmo
    wrote on last edited by Guy Gizmo
    #1

    I have a QTableView that accepts drops in order to rearrange and create new rows. So far, everything is working, except that if the user performs a drop in the area below the final row of the table, it doesn't accept the drop. What I'd like it to do in that case is draw an indicator as though the user was hovering over the lower half of the final row and then accept the drop, placing it after the last row.

    Since a picture is worth a thousand words:

    Here is what it looks like when the user drops an item in the lower half of the last row. An indicator appears correctly, and when the user releases the mouse, a new row is added to the table. This is what I want to happen if the user drops an item on to the QTableView in the area below the last row.

    Here is where I also want the user to be able to drop an item, but currently it does not work. Note the lack of indicator.

    So far I've tried subclassing QTableView and reimplementing dragMoveEvent() and dropEvent() methods in such a way that it calls into QTableView's version of these function, but I pass in a new QDragMoveEvent or QDropEvent with a position that is in the lower half of the last row. While it does draw an indicator like I want, it doesn't accept the drop so this method doesn't seem to work.

    I'm also aware I can set the stretchLastSection property to true for the vertical header of my QTableView, but this is unacceptable, as I need all the rows of my table view to be the same height.

    Is there any way to accomplish this? At this point I'm stumped!

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bsomervi
      wrote on last edited by
      #2

      This is handled by QAbstractItemModel::dropMimeData. It gets passed row and column arguments of -1 when the drop is to the parent of the view items.

      Guy GizmoG 1 Reply Last reply
      1
      • B bsomervi

        This is handled by QAbstractItemModel::dropMimeData. It gets passed row and column arguments of -1 when the drop is to the parent of the view items.

        Guy GizmoG Offline
        Guy GizmoG Offline
        Guy Gizmo
        wrote on last edited by
        #3

        @bsomervi You are correct. I'm not sure how I missed that, as I've already implemented the dropMimeData method.

        Is there any way to get the table view to display a drop indicator in this case, like when the dropping between existing rows?

        B 1 Reply Last reply
        0
        • Guy GizmoG Guy Gizmo

          @bsomervi You are correct. I'm not sure how I missed that, as I've already implemented the dropMimeData method.

          Is there any way to get the table view to display a drop indicator in this case, like when the dropping between existing rows?

          B Offline
          B Offline
          bsomervi
          wrote on last edited by
          #4

          @Guy-Gizmo said:

          Is there any way to get the table view to display a drop indicator in this case, like when the dropping between existing rows?

          Return QAbstractItemModel::flags(index) | Qt::ItemIsDropEnabled from QAbstractItemModel::flags(QModelIndex const& index) const where index is invalid.

          Guy GizmoG 1 Reply Last reply
          1
          • B bsomervi

            @Guy-Gizmo said:

            Is there any way to get the table view to display a drop indicator in this case, like when the dropping between existing rows?

            Return QAbstractItemModel::flags(index) | Qt::ItemIsDropEnabled from QAbstractItemModel::flags(QModelIndex const& index) const where index is invalid.

            Guy GizmoG Offline
            Guy GizmoG Offline
            Guy Gizmo
            wrote on last edited by
            #5

            @bsomervi I am already doing that, and while the cursor does change to show that the item can be dropped, it doesn't display the horizontal line indicator showing that it will be put below the last line of the table view.

            B 1 Reply Last reply
            0
            • Guy GizmoG Guy Gizmo

              @bsomervi I am already doing that, and while the cursor does change to show that the item can be dropped, it doesn't display the horizontal line indicator showing that it will be put below the last line of the table view.

              B Offline
              B Offline
              bsomervi
              wrote on last edited by
              #6

              @Guy-Gizmo said:

              @bsomervi I am already doing that, and while the cursor does change to show that the item can be dropped, it doesn't display the horizontal line indicator showing that it will be put below the last line of the table view.

              I do not think that is easy. The lines around/above items are drawn by the QStyle in drawPrimitive() when the primitive is PE_IndicatorItemViewItemDrop so that can be changed with a QProxyStyle but that mechanism is for view items. I can't see an easy way of indicating in the viewport below the items when dragging there.

              Guy GizmoG 1 Reply Last reply
              1
              • B bsomervi

                @Guy-Gizmo said:

                @bsomervi I am already doing that, and while the cursor does change to show that the item can be dropped, it doesn't display the horizontal line indicator showing that it will be put below the last line of the table view.

                I do not think that is easy. The lines around/above items are drawn by the QStyle in drawPrimitive() when the primitive is PE_IndicatorItemViewItemDrop so that can be changed with a QProxyStyle but that mechanism is for view items. I can't see an easy way of indicating in the viewport below the items when dragging there.

                Guy GizmoG Offline
                Guy GizmoG Offline
                Guy Gizmo
                wrote on last edited by
                #7

                @bsomervi Well, that's okay -- it's not that important that the indicator be there. Thanks for your help!

                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