How to enable drag row from QtableView(QSqlQueryModel) to other Qtableview(QAbstractTableModel)?



  • I need to be able drag row from QtableView A that is using QSqlQueryModel to simple QTableView B
    i followed few links in the net and implemented all info i could find , but still i even can't see the mouse indicator enable me to start the drag from table A and the method in table B not even triggered .
    in Table A (QSqlQueryModel)
    i set in flags
    @Qt::ItemFlags PlayListSqlModel::flags(
    const QModelIndex &index) const
    {
    Qt::ItemFlags defaultFlags = QSqlQueryModel::flags(index);

    if (index.isValid())
    return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags |Qt::ItemIsSelectable;

    return defaultFlags;
    }@

    in Table B i set :
    @Qt::ItemFlags PlayListPlayerModel::flags( const QModelIndex &index ) const
    {

    Qt::ItemFlags defaultFlags = QAbstractTableModel::flags(index);

    if (index.isValid())
        return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags |Qt::ItemIsSelectable;
    else
        return Qt::ItemIsDropEnabled | defaultFlags | Qt::ItemIsSelectable;
    

    }@

    also in table B i implemented all the drop methods in the model class



  • Hi,
    I was trying to do something similar ...drag from a QListWidget to a QTreeWidget. Adding
    @
    setAcceptDrops()
    @
    to 'true' (for QTreeWidget) worked for me.

    Hope this helps.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.