@Deneguil said in Custom QGraphicsEllipseItem mousePressedEvent single clicks:
@Asperamanca
Thank you very much for your in depth breakdown of the event propagation pipeline.
I originally wrote the following line to prevent both events from firing.
if(itemAt(event->pos()) != nullptr) return;
Without it it'd print both "GV clicked" and "State clicked".
If modified it to this one now and it works perfectly.
if(itemAt(event->pos()) != nullptr) {
QGraphics::mousePressEvent(event);
return;
}
Both strings are still printed without the return which is why it's still here for apart from that it's perfect.
Thank you!
However, this way you are bypassing a lot of things, which could lead to confusion the next time you'd like to add something.
What you probably want (I'm guessing a bit here) is this:
void GraphicView::mousePressEvent(QMouseEvent* event) {
QGraphicsView::mousePressEvent(event);
if(event->isAccepted()) return;
std::cout << "GV clicked\n";
}
Now you can catch the event in the item, handle and accept it.
The view will know that someone has taken care of the event, and it doesn't need to consider it.