Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.15, 6.x
-
Arch Linux, tested with both Qt 5.15 and Qt 6 but I guess the same issue would exist on other systems
Description
The problem is :
If I :
- click on item A with the left mouse button,
- while keeping my LMB mouse pressed, move over another item B,
- do a right-click which triggers a context menu from B,
- release my LMB over the context menu
Then item A never gets the "release" for its original LMB press, which breaks the expected state machine.
I tried forcing a mousegrab or focus on itemA but this does not prevent the context menu event in itemB.
Most interestingly, it is still A which gets a right mouse press event even when the cursor is over B and the context menu is B's.
Here's a repro (wanted to attach it but Jira complains about some missing tokens issue ?)
#include <QApplication> #include <QGraphicsScene> #include <QGraphicsView> #include <QGraphicsItem> #include <QGraphicsSceneMouseEvent> #include <QDebug> #include <QMenu> class itemA : public QGraphicsItem { public: itemA() { setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton); } void mousePressEvent(QGraphicsSceneMouseEvent* ev) override { qDebug() << "A press"; ev->accept(); } void mouseReleaseEvent(QGraphicsSceneMouseEvent* ev) override { qDebug() << "A release"; ev->accept(); } QRectF boundingRect() const override { return {0, 0, 40, 40}; } void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override { painter->fillRect(boundingRect(), Qt::blue); } }; class itemB : public QGraphicsItem { public: itemB() { setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton); } void contextMenuEvent(QGraphicsSceneContextMenuEvent* ev) override { qDebug() << "B contextmenu"; QMenu m; m.addAction("Foo"); m.addAction("Bar"); m.addAction("Baz"); m.exec(ev->screenPos()); ev->accept(); } QRectF boundingRect() const override { return {0, 0, 40, 40}; } void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override { painter->fillRect(boundingRect(), Qt::red); } }; int main(int argc, char *argv[]) { QApplication a(argc, argv); QGraphicsScene sc; auto ita = new itemA; auto itb = new itemB; ita->setPos(0, 0); itb->setPos(100, 0); sc.addItem(ita); sc.addItem(itb); QGraphicsView v{&sc}; v.show(); return a.exec(); }