PDA

View Full Version : QGraphicsItem mousePressEvent only on opaque pixels



jonks
14th February 2010, 23:39
Hi,

I'm trying to make my QGraphicsItem only respond to mousePressEvent's if the user clicks on opaque pixels of the item.

How should I go about doing this?

So far I think I have to obtain the raw pixels of the QGraphicsItem, but this seems to be very inefficient.
(I guess I need to render the QGraphicsItem to an off scene buffer, then do a x,y pixel lookup on the buffer).

Any ideas?

Thanks!

aamer4yu
15th February 2010, 11:24
I dont think mouse clicks are propogated for transparent pixels. But I guess you dont want clicks on semi transparent area also ?
If yes, then you can try 2 things -
1) Subclass QGraphicsItem and override the mousePressEvent. In that you can accept or ignore the event based on items . This is what u have posted and I too not sure how we can get a pixels value for a graphics item
2) You can override shape() function and return the path. This function is responsible where mouse can be clicked.. read the doc