0

I attached a QLineEdit to a subclass of QGraphicsScene. I noticed that the QGraphicsScene is also getting any mouse event (such as mouse press, mouse release, mouse move, etc) in addiction to the QLineEdit I attached. Is there any way to prevent the events from going through the QLineEdit and into the scene?

I attached it using:

scene->addWidget(lineEdit);

Any suggestions? Thanks!

K. Barresi
  • 1,275
  • 1
  • 21
  • 46

1 Answers1

1

http://qt-project.org/doc/qt-4.8/qmouseevent.html#details

http://qt-project.org/doc/qt-4.8/qt.html#WidgetAttribute-enum

Qt::WA_NoMousePropagation

Prohibits mouse events from being propagated to the widget's parent. This attribute is disabled by default.

Here is some more information specific to QGraphicsScene:

http://qt-project.org/doc/qt-4.8/qgraphicsscene.html#event-handling-and-propagation

For mouse-over effects, QGraphicsScene dispatches hover events. If an item accepts hover events (see QGraphicsItem::acceptHoverEvents()), it will receive a GraphicsSceneHoverEnter event when the mouse enters its area. As the mouse continues moving inside the item's area, QGraphicsScene will send it GraphicsSceneHoverMove events. When the mouse leaves the item's area, the item will receive a GraphicsSceneHoverLeave event.

All mouse events are delivered to the current mouse grabber item. An item becomes the scene's mouse grabber if it accepts mouse events (see QGraphicsItem::acceptedMouseButtons()) and it receives a mouse press. It stays the mouse grabber until it receives a mouse release when no other mouse buttons are pressed. You can call mouseGrabberItem() to determine what item is currently grabbing the mouse.

Community
  • 1
  • 1
phyatt
  • 18,472
  • 5
  • 61
  • 80
  • Thanks phyatt, that helped a lot – K. Barresi May 20 '13 at 22:48
  • I think the problem is that the scene keeps stealing focus. I never see the blinking text cursor. – K. Barresi May 20 '13 at 23:20
  • The proxy widgets in a qgraphicsscene are kind of weird. They kind of work. I've done a little bit with them in the past, and they don't get redrawn at the same rate as when they are in nested in a normal QWidget. You can also monitor what has the focus, and focus events just like mouse events. Good luck. – phyatt May 20 '13 at 23:31
  • Woah, just found a new class: http://qt-project.org/doc/qt-4.8/qgraphicsscenemouseevent.html – phyatt May 20 '13 at 23:52