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. Reordering rows of QTableView with drag and drop
Forum Updated to NodeBB v4.3 + New Features

Reordering rows of QTableView with drag and drop

Scheduled Pinned Locked Moved Unsolved General and Desktop
42 Posts 6 Posters 12.0k Views 4 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.
  • kshegunovK kshegunov

    @Max-Paperno said in Reordering rows of QTableView with drag and drop:

    For funsies, and to support my PoV that the item model is the proper interface to the data ;-), here's an option to toggle the drop behavior between move and overwrite using only the item model. It's @kshegunov 's solution but with a toggle switch to control the behavior. Items can still be dropped between lines to move them, in either mode. Most importantly, the QTableView::dragDropOverwriteMode remains false regardless (more on this below, after the code break).

    Thanks for the code. However it doesn't address @Rodrigo-B's question (which we both missed in fact):

    @Rodrigo-B said in Reordering rows of QTableView with drag and drop:

    Would it be possible to obtain the same behavior but overriding view methods only?

    So, I'd say yes, but you have to completely reimplement the dropEvent handler in the view and not delegate to the model.

    M Offline
    M Offline
    Max Paperno
    wrote on last edited by
    #41

    @kshegunov said in Reordering rows of QTableView with drag and drop:

    So, I'd say yes, but you have to reimplement the dropEvent handler in the view and not delegate to the model.

    Agreed. Which wouldn't be so bad, except the part one really wants to re-use is private (d->dropOn()) which further calls some other private utility methods and also updates a private member variable (dropIndicatorPosition). Everything except setting that private member could just be copied over (I think, and I"m not sure what the fallout would be from not setting dropIndicatorPosition properly), but... blech. I get why stuff should stay private (in d), but something like dropOn() (and a few other utilities) could be protected members of the main class w/out much danger of breaking BC down the line.

    https://code.woboq.org/qt5/qtbase/src/widgets/itemviews/qabstractitemview.cpp.html#_ZN17QAbstractItemView9dropEventEP10QDropEvent

    -Max

    kshegunovK 1 Reply Last reply
    0
    • M Max Paperno

      @kshegunov said in Reordering rows of QTableView with drag and drop:

      So, I'd say yes, but you have to reimplement the dropEvent handler in the view and not delegate to the model.

      Agreed. Which wouldn't be so bad, except the part one really wants to re-use is private (d->dropOn()) which further calls some other private utility methods and also updates a private member variable (dropIndicatorPosition). Everything except setting that private member could just be copied over (I think, and I"m not sure what the fallout would be from not setting dropIndicatorPosition properly), but... blech. I get why stuff should stay private (in d), but something like dropOn() (and a few other utilities) could be protected members of the main class w/out much danger of breaking BC down the line.

      https://code.woboq.org/qt5/qtbase/src/widgets/itemviews/qabstractitemview.cpp.html#_ZN17QAbstractItemView9dropEventEP10QDropEvent

      -Max

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #42

      Which gets me to my original position. I'd rather have this whole d&d ripped out of the model, and probably out of the view and put inside a delegate (i.e. one that's aggregated) which handles the logic and propagates down to the model how and what should be modified. But as said, such things aren't happening any time soon.

      Read and abide by the Qt Code of Conduct

      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