Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore mouse events over transparent parts of an svg image in qgraphicsview?

I am working on a graphics view (using C++ and Qt) which contains quite a few svg images. I intercept clicks on them, but i'd like not to receive events (or to be able to ignore them) when mouse is over transparent parts of svg items.

Is it possible ?
Should svg files be specifically designed for such use ?
Is there some hidden Qt option i have not (yet) heard of ?

like image 439
Benoît Avatar asked Feb 17 '11 08:02

Benoît


2 Answers

There's a CSS property which can be applied to SVG elements, pointer-events, though the default for this is visiblePainted:

The given element can be the target element for pointer events when the ‘visibility’ property is set to visible and when the pointer is over a "painted" area. The pointer is over a painted area if it is over the interior (i.e., fill) of the element and the ‘fill’ property has an actual value other than none or it is over the perimeter (i.e., stroke) of the element and the ‘stroke’ property is set to a value other than none.

Which would indicate that Qt graphics view doesn't support it.

like image 145
robertc Avatar answered Sep 23 '22 19:09

robertc


Having no other choice but to find out the hard way the answer to my question, here is what i did :

  • looked for mousePressEvent definition in QGraphicsSvgItem.cpp. Found none.
  • looked for mousePressEvent definition in QGraphicsItem.cpp (ancestor of QGraphicsSvgItem). The method exists but no relevant action could be found there.
  • looked for mousePressEvent calls in QGraphicsItem.cpp. Found myself reading the code of QGraphicsItem::sceneEvent(), dispatcher of mouse events for a Qt graphics scene. There does not seem to be any sort of differentiating different zones of graphic items.

Hence the sad answer : Qt does not permit such a behaviour.

like image 24
Benoît Avatar answered Sep 23 '22 19:09

Benoît