QGraphicsScene hover*Events to all item under mouse cursor.
-
Hello!
I am making an application that is similar to the Diagram Scene Example. I expanded it by adding a resizer item(SizeGripItem) and in the future, I want to add a slightly similar element in the structure. And they all use hover*Events.
The problem is that both of these items(SizeGripItem and another "future item") are child of the DiagramItem, and they lie on top of the parent. So all hover*Events are received by the element that was added last. In fact, they all get it, but in the wrong way. For example, hoverMoveEvent works only once when it enters the child's shape. Which is not typical for this event. I tried this option from the StackOverflow post. It says that you need to redefine QGraphicsView or QGraphicsScene mouseMoveEvent and send events using QGraphicsScene::sendEvent, but it seems to me that this is a bit of a crutch way. Because as I understood it, I would have to implement the full logic of all hover events from scratch. I also tried to call event->ignore(), but the documentation says that this has no effect.The looks of the DiagramItem with SizeGripItem and "future item" when it's hovered.
The looks of the DiagramItem with SizeGripItem and "future item" when it's
not hovered.
Thanks for any help or suggestions that will help solve this problem.
-
@SGaist
Out of curiosity, why are you making three different items for what seems to be only one in the end ?I realized that my mistake was that I was creating separate elements when only one is created in the end. Having redone this, everything worked as it should. Thank you!
-
Hi and welcome to devnet,
What about reverting the order of the items ?
-
@SGaist Please excuse me if I misunderstand something. But as I understand it, you want me to make children as the parent of the DiagramItem? That is:
From this:
DiagramItem
|_SizeGripItem
|_"future item"To this:
SizeGripItem
|_DiagramItem"future item"
|_DiagramItemBut is that really to have more than one parent? Sorry for not showing the hierarchy initially.
-
I meant to stack them differently, so future on top of size grip on top of main item.
Are you grouping them ?
-
@SGaist No, I'm not grouping them, just parenting. Here is the code of how item is created. ArrowManager is "future item". Just temporary name.
DiagramItem *DiagramScene::createDiagramItem(int diagramType) { DiagramItem* diagramItem = new DiagramItem(DiagramItem::DiagramType(diagramType)); SizeGripItem* sizeGripItem = new SizeGripItem(new PathResizer, diagramItem); new ArrowManager(diagramItem); connect(sizeGripItem, &SizeGripItem::resizeBeenMade, diagramItem, &DiagramItem::updateTextItemPosition); connect(diagramItem, &DiagramItem::itemPositionChanged, this, &DiagramScene::drawLevelLineWithItemOnSameAxis); connect(diagramItem, &DiagramItem::itemReleased, this, &DiagramScene::deleteAllLevelLines); return diagramItem; }
-
Out of curiosity, why are you making three different items for what seems to be only one in the end ?
-
-
Can you share a minimal compilable example ?
That will allow to better understand your implementation and what is happening.
-
@SGaist Of course, but it will take some time. How is it convenient for you to provide the code? Should I leave the pieces of code here in this way:
DiagramItem.h
// DiagramItem definition code // ...
DiagramItem.cpp
// DiagramItem implementation code // ...
etc
// ...
or in some other way?
Thank you so much for your support!
-
Either that or if you have a GitLab/GitHub/BitBucket/Other repo.
-
@SGaist
Out of curiosity, why are you making three different items for what seems to be only one in the end ?I realized that my mistake was that I was creating separate elements when only one is created in the end. Having redone this, everything worked as it should. Thank you!