Hi,
I'd like to sort items in a tree view by dragging and dropping.
My data is a flat list of rows and columns with no heirarchy. I chose not to use TableView as the row headers cant be hidden, is this right ?
I've got as far as subclassing standardItemView and re implementing :
supportedDropActions() const
removeRows(int row, int count, const QModelIndex &parent)
My trouble is what to put in removeRows so that a MoveAction is done on the model. At the moment I get copying of data in the view.
Another problem is that when dragging the treeView item, I get a row with a + as its a treeView Im using, any ideas where I'm going wrong.
Below is what I've got so far
{
}
Qt::DropActions MyModel::supportedDropActions() const
{
return Qt::MoveAction;
}
bool MyModel
::removeRows(int row,
int count,
const QModelIndex &parent
) {
if (parent.isValid())
return false;
beginRemoveRows(parent, 0, 0);
// What am I doing here?
endRemoveRows();
return true;
}
MyModel::MyModel(QObject *parent)
: QStandardItemModel(parent)
{
}
Qt::DropActions MyModel::supportedDropActions() const
{
return Qt::MoveAction;
}
bool MyModel::removeRows(int row, int count, const QModelIndex &parent)
{
if (parent.isValid())
return false;
beginRemoveRows(parent, 0, 0);
// What am I doing here?
endRemoveRows();
return true;
}
To copy to clipboard, switch view to plain text mode
Bookmarks