首页 > 解决方案 > 自定义 QGraphicsPolygonItem dragLeaveEvent 未执行

问题描述

我有一个自定义版本的 QGraphicsPolygonItem,称为 CustomGPolygon。

在 customgpolygon.h 我已经声明了函数void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);

customgpolygon.cpp 中的函数如下所示

void CustomGPolygon::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
{
    event->setAccepted(true);
    qDebug() << "hi";
}

在这些多边形的构造函数中,我调用setAcceptDrops(true);.

我面临的问题是移动多边形时,控制台中不显示“hi”。

任何帮助表示赞赏!

标签: c++qt

解决方案


您必须在某处为 CustomGPolygon 的对象ItemIsMovable( doc ) 设置标志:

void setFlag(QGraphicsItem::ItemIsMovable, true);

推荐阅读