문제

I have a QGraphicsScene where I'm inserting various QGraphicsItem objects like rectangles or polygons. The idea is to represent an electronic diagram with a RectItem for each component, a triangle-shaped PolygonItem for each pin of this component, and a PathItem to represent the links between the pins.

I'm having a hard time figuring out a way to properly arranged my items so the links are always hiding by their start pin and end pin. It's easy to hide the link behind its start pin, because the start pin is always the parent of the link, and therefore I can set the flag QGraphicsItem::ItemStacksBehindParent when I create my link. But for the end pin, I'm stuck.

I tried to set the Zvalue of my pin to a superior value of the link it is attached, or to call the Qt function StackBefore(), but without result. The doc tell me that the z-order concern only sibling items, that mean item that share the same parent or are both top-level items. But all my components are independant, so is there a way to change the stack order between two non-sibling items?

Thank you very much for your help.

도움이 되었습니까?

해결책

Well, based on Riateche comments (thank you), I was able to find a solution to my problem.

In order to modify the stacking order between two non-sibling item, and because they have no common parents, I had to change the z-value of their topmost parent, ie the ones who are top-level items. Instead of trying to hide my link behind its end pin, I made the whole component, the one which contains the pin which emits my link, hide behind the other component, the one which are parent of the end pin. Because those two components are top-level items, the setZValue method works.

Well, I agree that it doesn't really answer the original question, because, eventually, I had to rethink the problem in order to use two sibling/top-levels items, but it feels like the natural way of doing things, so... I don't think that there really exist a way to change the stack order between two non sibling items.

다른 팁

I suggest creating the links without a parent.
Then use one lower (range of) z-index for all links and one higher (range) for all components.
This way the stacking is always right, and you are safe for the case when there is a (e.g. feedback) loop in your diagram.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top