拖放QListView项目
问题描述:
请帮我解决这个问题....我的左侧有QListView
,另一侧有QWidget
。在QListView
我添加了一些使用QStandardItem
的项目。现在,我想将QListView
项目拖放到另一侧QWidget
,我也必须对QWidget
执行相同的操作。我可以拖放我QListView
项目的QListView
自身内部使用拖放QListView项目
listView.setAcceptDrops(true);
listView.setDragEnabled(true);
listView.setDragDropMode(QAbstractItemView::InternalMove);
这是工作单独而QListView内部罚款。我想拖放QListView项目到其他的小部件。我怎样才能做到这一点?我知道,我必须处理的事件,如
void dropEvent(QDropEvent *);
void dragMoveEvent(QDragMoveEvent *);
void dragEnterEvent(QDragEnterEvent *);
void mousePressEvent(QMouseEvent *);
我只是想它像这样
void Example::dragMoveEvent(QDragMoveEvent *e)
{
// The event needs to be accepted here
e->accept();
}
void Example::dragEnterEvent(QDragEnterEvent *e)
{
// Set the drop action to be the proposed action.
e->acceptProposedAction();
}
void Example::dropEvent(QDropEvent *e)
{
qDebug("Items Dropped");
}
正如我刚才一些qDebug(),这是工作尝试当我拖动来自我的QListView
的物品并将其放在QWidget
中,并且我的输出为“物品已褪色”。 但我不知道如何把我的确切QListView
的项目在这里。
答
您不必为视图创建子类。所有拖放的东西都由模型处理,因此您必须继承您的标准模型。你可能想看看model subclassing reference。当然,您还必须将视图的拖放模式更改为QAbstractItemView::DragDrop
以获得外部拖放。