Is there a way to allow mouse clicks to pass to object beneath

I have some overlaying objects on top of a larger object. Is there a way that when clicking on these overlaying objects the event for the object beneath is executed. I know I can group them and put the code there but was wondering if there is a way to pass it through?

You could do a hit-test in the OnMouseClicked event of your overlaying component.

I was able to implement this with custom methods named “clicked” on various vision components. A semi-transparent rectangle overlays all the components and performs the hit-tests.

Here’s the hit-test code:

from com.inductiveautomation.vision.api.client.components.shapes import PathBasedVisionShape

for comp in event.source.parent.getComponents():
	if comp == event.source:
		continue
	if isinstance(comp, PathBasedVisionShape):
		if comp.getBoundingRect().contains(event.point):
			comp.clicked()
	else:
		if comp.bounds.contains(event.point):
			comp.clicked()

It’s necessary to perform the type check before the hit-test because only shapes have the getBoundingRect() method. Curiously, the bounds property of vision shapes doesn’t store the actual layout information. For most standard vision/swing components, component.bounds works fine.

2 Likes