请帮我解决这个问题..。我左边有一个QListView,另一边有一个QWidget。在QListView中,我使用QStandardItem添加了几个项目。现在,我想将QListView项拖放到另一边,QWidget,我也必须对QWidget做同样的操作。可以将QListView项拖放到QListView本身中,方法是
listView.setAcceptDrops(true);
listView.setDragEnabled(true);
listView.setDragDropMode(QAbstractItemView::InternalMove); 这在QListView内部运行得很好。我希望将QListView项拖放到另一个Widget中。我该怎么做?我知道我必须处理这些事情
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中,并在"Items Drop“时获得输出时,这是有效的。但是我不知道怎么把我的QListView__'s的东西带过来。
发布于 2012-10-20 12:48:44
您不必对视图进行子类化。所有的拖放操作都由模型处理,因此您必须对标准模型进行子类化。您可能想看看模型子类参考。当然,您还必须将视图的拖放模式更改为QAbstractItemView::DragDrop,以获得外部拖放。
https://stackoverflow.com/questions/12916324
复制相似问题