0

Hello in my application i'm making a QGraphicsView and set the scene on it:

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();

my 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 is my QGraphicsProxyWidget and the problem is that it has weird boundaries, i need to implement some animation on hover of my control TestIcon, (i done that using event filter) mouse enter and mouse leave fires when i drag my mouse on a random places, not only on my TestIcon control. If do not add my control to the QGraphicsScene hover detection works fine, so i assume this is a scene/proxywidget problem. Is there a way i can set size or boundaries to QGraphicsProxyWidget to stop that?

SirLanceloaaat
  • 213
  • 9
  • 18

1 Answers1

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.

TheDarkKnight
  • 27,181
  • 6
  • 55
  • 85
  • Sorry i forgot the code which creates QGraphicsProxyWidget.Yes im placing a widget on scene using `scene->addWidget(TestIcon);` and event filter for hover is installed on TestIcon. rotateIcon is my QGraphicsProxyWidget. – SirLanceloaaat Jul 31 '13 at 16:11
  • After adding my widget on scene, hover detection breaks. – SirLanceloaaat Jul 31 '13 at 16:17
  • Please add all the code and explain what you mean by 'breaks'. – TheDarkKnight Jul 31 '13 at 16:22
  • I updated my first post, and added the code. By 'breaks' i mean that the QEvent::Enter and QEvent::Leave fires not only when the mouse is entering leaving my control but also when its over other random places on the QGraphicsScene. If i do not add my ui->TestIcon to the QGraphicsView QGraphicsScene detection works fine. – SirLanceloaaat Aug 01 '13 at 00:34
  • You get the proxy, rotateItemIcon, but no where in your code do I see that you're setting its geometry. – TheDarkKnight Aug 01 '13 at 07:47
  • hello, i tried to use this: `rotateItemIcon = scene->addWidget(ui->TestIcon); rotateItemIcon->setGeometry(QRectF(285,14,26,26));` but it didn't help me. – SirLanceloaaat Aug 01 '13 at 08:59
  • Then I think the problem lies in other code that we haven't seen here. – TheDarkKnight Aug 01 '13 at 09:10
  • I posted all the code that initialize my QGraphicsScene, i don't know what should i add. – SirLanceloaaat Aug 01 '13 at 10:07
  • Your problem really does sound like the proxy is returning a much larger area than it should. Instead of adding the widget to get a proxy, subclass QGraphicsProxyWidget and add the widget to that. Then add that to the scene. You can then overload the boundingRect function and put a breakpoint on it to see what it returns. That function will be called, amongst other reasons, to test if your mouse is over it. – TheDarkKnight Aug 01 '13 at 10:55