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
from PyQt4.QtCore import Qt, QRect
from PyQt4.QtGui import QApplication, QMainWindow, QGraphicsScene, QPushButton,
QGraphicsView, QRegion, QWidget, QVBoxLayout
def gotAClick():
print "Got a click";
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
button1 = QPushButton("1111111");
button2 = QPushButton("2222222");
button1.clicked.connect(gotAClick)
button2.clicked.connect(gotAClick)
graphics_scene = QGraphicsScene();
graphics_view = QGraphicsView(graphics_scene);
graphics_scene.addWidget(button1)
window = QMainWindow();
main_widget = QWidget();
main_layout = QVBoxLayout();
main_layout.addWidget(graphics_view);
main_layout.addWidget(button2);
main_widget.setLayout(main_layout);
window.setCentralWidget(main_widget);
window.show();
button1.setMask(QRegion(QRect(0,0,button1.width()/2, button1.height())));
button2.setMask(QRegion(QRect(0,0,button2.width()/2, button2.height())));
sys.exit(app.exec_())_______________________________________________
PyQt mailing list [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt