0

您好,在我的应用程序中,我正在制作 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 的大小或边界来阻止它?

4

1 回答 1

0

I'm not sure if I completely understand your question, but it sounds like you're have a widget placed in a scene via a QGraphicsProxyWidget and when you try to detect if your mouse is over the widget you want it to animate.

By 'weird boundaries' I assume you mean the extents to which the proxy widget is accepting the mouse as being over the widget. If so, I suggest either calling setGeometry on the QGraphicsProxyWidget to set its position and dimensions, or inherit from QGraphicsProxyWidget and implement the boundingRect function to define the area of the proxy widget.

于 2013-07-31T15:49:37.750 回答