您好,在我的应用程序中,我正在制作 QGraphicsView 并在其上设置场景:
QGraphicsProxyWidget *rotateItemIcon;
HoverFilter *hv = new HoverFilter(); // my hover filter class
connect(hv,SIGNAL(SignalHover(QObject*)),this,SLOT(ObjectHover(QObject*)));
connect(hv,SIGNAL(SignalHoverLeave(QObject*)),this,SLOT(ObjectHoverLeave(QObject*)));
ui->TestIcon->installEventFilter(hv);
...
scene = new QGraphicsScene(this);
scene->setSceneRect(0, 0, 661, 255);
ui->TestIcon->setParent(NULL);
rotateItemIcon = scene->addWidget(ui->TestIcon); // here i add my control to the scene and receive QGraphicsProxyWidget object
rotateItemIcon->setTransformOriginPoint(ui->TestIcon->width()/2,
ui->TestIcon->height()/2);
ui->graphicsViewFive->setScene(scene); //QGraphicsView on my form
ui->graphicsViewFive->show();
我的 HoverFilter.cpp
#include "hoverfilter.h"
#include "QDebug"
HoverFilter::HoverFilter()
{
}
bool HoverFilter::eventFilter( QObject *dist, QEvent *event )
{
if( event->type() == QEvent::Enter )
{
emit SignalHover(dist);
return true;
}
if( event->type() == QEvent::Leave )
{
emit SignalHoverLeave(dist);
return true;
}
return false;
}
rotateItemIcon 是我的 QGraphicsProxyWidget 问题是它有奇怪的边界,我需要在我的控件 TestIcon 悬停时实现一些动画,(我使用事件过滤器完成了)当我将鼠标拖动到随机位置时鼠标进入和鼠标离开火灾,不仅在我的 TestIcon 控件上。如果不将我的控件添加到 QGraphicsScene 悬停检测工作正常,那么我认为这是一个场景/代理小部件问题。有没有办法可以设置 QGraphicsProxyWidget 的大小或边界来阻止它?