[PyQt] Bug with QWidget masks in QGraphicsScene?

Jeremy jgillula+pyqt at gmail.com
Fri Jun 11 22:26:34 BST 2010


Hi Matteo,

First, thanks for your reply!  Unfortunately, I'm not sure your solution 
would work for what I'm trying to do (as is).  In essence, I'm trying to 
create a GUI with several irregularly shaped buttons, whose bounding 
boxes overlap (but not the actual shapes).  (For example, think of a 
rectangle cut across the diagonal -- each resulting triangle would be a 
button.)  I guess I could subclass QGraphicsScene, and add a method to 
register the buttons' masks with the scene, and create my own logic for 
determining which button should receive a click event when someone 
clicks on the scene (by redefining mousePressEvent, as you suggested).

I suppose that's what I'll do, until someone can determine if this is a 
bug or the proper behavior.

Thanks for the suggestion!  I wouldn't've thought of it otherwise.

 - J

Matteo Boscolo wrote:
> Hi Jeremy,
> I did some test and I notice that if you use the ..
> graphics_view.setMask(....)
> you get the get some problem.
>
> I do not why The view work in this way..I'm not so skilled in qt to help
> you.
>
> But a work around could be:
>
> graphics_scene.mousePressEvent =myMouseEvent #to get the mouse click event
> ..
>
> def myMouseEvent(event):
> 	#if event is in region:
> 		event.ignore()
>
> Regards,
> Matteo
>
> -----Original Message-----
> From: pyqt-bounces at riverbankcomputing.com
> [mailto:pyqt-bounces at riverbankcomputing.com] On Behalf Of Jeremy
> Sent: 11 June 2010 19:47
> To: pyqt at riverbankcomputing.com
> Subject: [PyQt] Bug with QWidget masks in QGraphicsScene?
>
> Hello,
>
> I have a question (which may stem from either a bug in PyQt, Qt, or just my
> understanding of how Qt is supposed to work). In particular, according to
> the Qt documentation
> (http://doc.trolltech.com/4.6/qwidget.html#setMask) masked widgets are only
> supposed to receive mouse events on their visible portions. This works fine
> on a normal widget in a GUI, but doesn't seem to be the case if I add a
> widget to a QGraphicsScene via the addWidget method.
>
> In particular, some example code is attached.  In this example I create two
> buttons, and place one in a QGraphicsScene and the other as part of a normal
> layout. I then add a simple mask so that only the left half of each button
> is visible. Then, if I click the non-visible part (right
> half) of the normal-layout-button, nothing happens (which seems like the
> correct behavior). But if I click the invisible right half of the
> QGraphicsScene button, the button still appears to be receiving the mouse
> click event.
>
> So, my question is...is this a bug in PyQt? Or does the same behavior happen
> under Qt in other languages? Or is it not a bug at all, and QWidgets are not
> supposed to respect their masks with regard to mouse events when added to
> QGraphicsScenes? Or am I just totally crazy? ;-)
>
> Any advice or suggestions anyone can provide would be very much appreciated!
>
> - Jeremy
>
>   


More information about the PyQt mailing list