0

Within a QTreeView, I would like to copy rows around by drag and drop. The corresponding Drag & drop settings look like:

this->setDragDropMode( QAbstractItemView::DragDrop );
this->setDropIndicatorShown( true );

This works fine unsing for the columns of the underlying QStandardItemModel which are visualised by the QTreeView. But not all columns of the model are visualised (see Hide future columns of QStandardItemModel in QTreeView):

    void MyViewClass::columnCountChanged(int p_nOldCount , int p_nNewCount )
    {
    QTreeView::columnCountChanged( p_nOldCount, p_nNewCount );

    for ( int i = MyViewClass::m_nColumnType; i < p_nNewCount; ++i )
    {
        setColumnHidden( i, true );
    }
}

How can I copy the whole row of a QStandardItemModel by drag and drop in the QTreeView when not all columns are visualised by the QTreeView?

Community
  • 1
  • 1
Tob
  • 286
  • 1
  • 17

1 Answers1

0

Found the solution:

One has to inherit / implement the QAbstractModel functions:

  • virtual QMimeData * mimeData(const QModelIndexList &indexes) const;
  • virtual bool dropMimeData(const QMimeData *p_grData, Qt::DropAction p_grAction, int p_nRow, int p_nColumn, const QModelIndex &p_grParentIdx);
  • virtual QStringList mimeTypes() const;

while mimeData needs to encode the data and dropMimeData needs to decode the data and needs to insert a new row / column with the draged data.

Tob
  • 286
  • 1
  • 17