Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QTableView prevent internal movement



  • 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



  • 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.


Log in to reply