سؤال

I'm having trouble with overloading mouseMoveEvent.

I have subclassed QGraphicsView and overloaded mousePressEvent, mouseMoveEvent and mouseReleaseEvent. I am using these events to draw a custom QGraphicsItem - which is a Line. (mousePress - sets the start point of the line, mouseMove makes the line follow the cursor, second mousePress sets the end point of the line and mouseRelease stops the drawing of the line.)

I have also created another custom item - Node. The node is drawn with a mousePress event. I have 2 flags to differentiate between drawing Lines and Nodes. The ItemIsMovable flag of the Node is set to true and I have reimplemented mouseMoveEvent in the Node class to make it move (I change its coordinates and repaint it. And it worked fine.)

The problem is - when I implemented the mouseMoveEvent in my subclass of QGraphicsView(for the drawing of the Line) - the mouseMoveEvent of the Node class stopped working and the Nodes aren't moving anymore. How can I fix this?

Thank you for your time, your help will be appreciated.

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

المحلول

You need to call base class (QGraphicsView) implementation from your implementation. Otherwise mouse events will not be processed by QGraphicsView and will not be passed to the scene and its items.

void MyView::mousePressEvent(QMouseEvent* e) {
  QGraphicsView::mousePressEvent(e);
  //your implementation
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top