سؤال

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!

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top