• 7787阅读
  • 4回复

[提问]sceneEventFilter不响应 [复制链接]

上一主题 下一主题
离线liuxu_lx7
 
只看楼主 倒序阅读 楼主  发表于: 2011-06-24
派生QGraphicsItem类, 在构造函数中设置:installSceneEventFilter(this)。重写sceneEventFilter。

按照我的理解,当这个派生类有事件发生时,应该先调用重写的sceneEventFilter函数。但是却没有

哪里错了呢?让sceneEventFilter响应应该具备哪些条件?有朋友了解么?
离线liuxu_lx7
只看该作者 1楼 发表于: 2011-06-24
在Output地方发现以下log:
QGraphicsItem::installSceneEventFilter: event filters can only be installed on items in a scene.

在google上查找:
Installs an event filter for this item on filterItem, causing all events for this item to first pass through filterItem's sceneEventFilter() function.

To filter another item's events, install this item as an event filter for the other item. Example:

An item can only filter events for other items in the same scene. Also, an item cannot filter its own events; instead, you can reimplement sceneEvent() directly.

Items must belong to a scene for scene event filters to be installed and used.
没理解
离线jianxin.jin
只看该作者 2楼 发表于: 2011-06-24
你说的这个问题貌似我遇到了,不过我重写的是installEventFilter()这个方法,这个里面可以正常的收到信号
离线liuxu_lx7
只看该作者 3楼 发表于: 2011-06-24
installSceneEventFilter 和 sceneEventFilter 都在QGraphicsItem写好, sceneEventFilter可以响应了。

可仍然有上面的 “警告日志”

我做的东西是:在QGraphicsScene中放置一个 QGraphicsItem, 在QGraphicsItem上需要放置一个QComboBox。想实现:点击QGraphicsItem或QComboBox都触发选中QGraphicsItem。
离线liuxu_lx7
只看该作者 4楼 发表于: 2011-06-24
回 2楼(jianxin.jin) 的帖子
感谢回复。

installEventFilter 我也用了。但是它是针对QWidget的。但,即使同时继承QObject和QGraphicsItem,它还是不起作用的。事件无法进入。

因为我在QGraphicsItem内嵌套了QWidget,所以不得不2种过滤事件的方法同时使用。
快速回复
限100 字节
 
上一个 下一个