c++ - 自定义 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”。
任何帮助表示赞赏!
解决方案
您必须在某处为 CustomGPolygon 的对象ItemIsMovable
( doc ) 设置标志:
void setFlag(QGraphicsItem::ItemIsMovable, true);
推荐阅读
- python - 如何将 Google Cloud bigquery 安装到 python?
- python - 为什么 reversed() 会删除线程安全?
- jenkins - Jenkins P4 插件:p4sync 无法同步 Unicode 文件
- multithreading - “内核线程仍然可能有点昂贵,因为需要系统调用才能在线程之间切换”到底是什么意思?
- kotlin - 如何正确加入在 CoroutineScope 中启动的所有作业
- php - 错误:作曲家需要锥体开发/集市
- sql - SQ 写作查询
- postgresql - PostgreSQL 升级到版本 12 - 没有 oid 的更改表太慢
- python - __init__() 应该为使用 boost_python 的 python 模块返回 None,而不是“NoneType”
- r - 将解决方案更改为更有效的解决方案