View Full Version : Mimic behaviour across QGraphicsViews

4th August 2014, 23:09
I have two subclassed QGraphicsViews in my application. When the mouse is dragged in the one, I want to mimic this drag in the other QGraphicsView. At first I thought I could just catch the QMouseEvent in the active view and pass it to the other using a signal/slot combination, but although I can confirm that the event is received, no drag takes place. Here is some code to illustrate what I mean:

void MyQGraphicsView::mousemoveEvent(QMouseEvent* event) {
// here some other stuff happens
emit signalFakeMouseMoveEvent(event);

// connected to the signalFakeMouseMoveEvent of the other MyQGraphicsView
void MyQGraphicsView::slotFakeMouseMoveEvent(QMouseEven t* event) {
QGraphicsView::mouseMoveEvent(event); // the correct event is received here

I have confirmed that the correct QMouseEvent is received in the lower of the two snippets given above, but only the active view is dragged.

I am wondering if a drag event in QGraphicsView is implemented in more than just QGraphicsView::mouseMoveEvent. Can anyone shed any light on how to achieve this? Thanks!

The alternative would be for me manually to compute the distance dragged, and send this to the other view, but this comes with all kinds of headaches such as dealing with the case when a view is dragged more than allowed. I would rather avoid this.

5th August 2014, 09:38
You could try connecting each view's scrollbars with those of the other view.