好的,我已经能够在QGraphicsScene
上进行拖放工作,而不是QGraphicsView
。我的代码看起来像这样:
class GraphicsView : public QGraphicsView
{
public:
GraphicsView(QGraphicsScene *scene) : QGraphicsView(scene) {}
protected:
void dragEnterEvent(QGraphicsSceneDragDropEvent *event)
{
event->setAccepted(true);
update();
}
void dragMoveEvent(QGraphicsSceneDragDropEvent *event)
{
event->setAccepted(true);
update();
}
void dropEvent(QGraphicsSceneDragDropEvent *event)
{
//stuff that never runs...
update();
}
};
尽管如此,此代码与QGraphicsScene
继承而非QGraphicsView
完全正常。我还运行了setAcceptDrops(true)
函数。我做错了什么?