[PyQt] Bug with QWidget masks in QGraphicsScene?

Matteo Boscolo matteo.boscolo at boscolini.eu
Fri Jun 11 20:53:07 BST 2010

Hi Jeremy,
I did some test and I notice that if you use the ..
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

But a work around could be:

graphics_scene.mousePressEvent =myMouseEvent #to get the mouse click event

def myMouseEvent(event):
	#if event is in region:


-----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?


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