PDA

View Full Version : Event detection in non-rectangular region



xdn
11th November 2015, 10:07
Hi,

I have a custom widget which contains some custom drawn areas that should be sensitive to events (e.g. mouse clicks).
The areas are not always rectangular.
Is there any Qt way of determining whether or not a click took place inside one of these arbitrarily shaped areas (setting some event-sensitive mask on the widget or sth...)?

Thanks,
xdn

anda_skoa
11th November 2015, 12:34
Since this is a custom widget, you can do anything you like with the mouse events you get.
So you can test the coordinates of the events against any arbitrary criteria and decide upon success/failure whether to accept or reject the event and whether to do something in response.

Cheers,
_

xdn
11th November 2015, 12:57
Implementing my own checks would was my first idea as well.
I just wanted to ensure that there is no Qt mechanism that would save me the time to do this.

anda_skoa
11th November 2015, 16:06
Ah, no, there isn't.

Depending on how you draw you might be able to re-use data though, e.g. QPainterPath, QRegion, etc.

Cheers,
_