简体   繁体   中英

Qt: mouseMoveEvent and interfer with hoverEnterEvent of child object

I use QGraphicsView to create a sort of circut editor, which has elements in it, which have connectors. It should be possible to connect those connectors with wires. However, I have a problem, while I drag from one connector to another, Qt grabs mouse, and other connectors stop receiving hoverEnterEvent . Btw, on hover connectors resize, so it's easier to hit them.

Once again, is it possible not to grab mouse while drag?

I have used Qt 4.5 for Windows.

As requested, here are some sources: http://pastebin.com/m422b9495

It is somewhat typical to change the mouse-over behavior during a drag operation. Widgets that normally respond to mouse movement tend to not respond during a drag unless they can receive the associated drop. So the usual hover events are suppressed. (Checking whether or not a widget accepts some drops is inadequate since the question is whether or not the widget might accept this drop.) Try using the drag's enter and leave events to resize your connectors, in addition to the hover events.

You could use the mouseMoveEvent in the source item to check when the cursor is over the target item.

For example:

def mouseMoveEvent(self, event):
    item = self.scene().itemAt(event.scenePos(), self.scene().views([0].transform())

    if isinstance(item, NodeConnectionGraphicItem):
        if self.item_over_drag is None:
            self.item_over_drag = item
            item.highlighted_mouse_over = True
            ...
            item.update()
    elif self.item_over_drag is not None:
        self.item_over_drag.highlighted_mouse_over = False
        self.item_over_drag.update()
        self.item_over_drag = None

I think you need to set interactive mode to false.

See also DragMode

ScrollHandDrag

The cursor changes into a pointing hand, and dragging the mouse around will scroll the scrolbars. This mode works both in interactive and non-interactive mode.

RubberBandDrag

A rubber band will appear. Dragging the mouse will set the rubber band geometry, and all items covered by the rubber band are selected. This mode is disabled for non-interactive views.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM