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 prevent internal movement
Qt 6.11 is out! See what's new in the release blog

QTableView prevent internal movement

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 523 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.
  • TobyT Offline
    TobyT Offline
    Toby
    wrote on last edited by
    #1

    Hi guys

    i have implemented a Drag/Drop inside a subclassed QAbstractTableModel.
    It works perfectly if i move stuff from one table to another:

    • removeRows gets called at the sourcemodel -> Job Done

    But in case i move a row inside the table, it gets cloned, because:

    • removeRows isn't called, moveRows isn't called either.

    How can i implement a working move inside the same table
    OR
    prevent "internal movement" ?

    greetings
    Toby

    1 Reply Last reply
    0
    • TobyT Offline
      TobyT Offline
      Toby
      wrote on last edited by
      #2

      Don't know if that is a good solution, but i found one:

      bool MyModel::canDropMimeData( const QMimeData *data, Qt::DropAction action, int, int, const QModelIndex & ) const
      {
          if ( action != Qt::MoveAction )
              return false;
          auto m = dynamic_cast<const UserDefinedMimeData*> ( data );
          if ( !m )
              return false;
          return m->sender() != this;
      }
      
      

      I am using a subclassed QMimeData anyway, so i added a const-Pointer to the sourcemodel to the Mimedata and compared that pointer inside "canDropMimeData()" of the destinationmodel with "this". If they are equal the drop is blocked.

      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