[Solved] Nested QGraphicsItems drawing positions
I’m new to Qt and really loving it so far. But I’m stuck on getting nested graphics items to draw properly. Here’s what I’ve done so far:
I’ve derived a class from QGraphicsItem, call it ComponentView. This class has 3 nested QGraphicsEllipseItems. The appearance should be a rounded rectangle for the main item, with the ellipses arranged along the edges. I set it up like this in the constructor:
- //
- // Set the connector size
- input1->setRect(sizeRect);
- output1->setRect(sizeRect);
- output2->setRect(sizeRect);
- //
- // Put the connectors into position
- input1->translate(-57, 10);
- output1->translate(43, 10);
- output2->translate(43, 30);
The paint function is:
- void BeamSplitterView::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
- {
- drawNodeBase(painter, option);
- input1->paint(painter, option, widget);
- output1->paint(painter, option, widget);
- output2->paint(painter, option, widget);
- }
where drawNodeBase() just draws a rounded rectangle and a text label. The problem is that FOUR ellipses are being drawn; the three on the edge plus one in the middle of the parent (at 0,0). I actually suspect that all three of the ellipse objects are being drawn in the middle, as well as in their proper positions. I don’t want the ellipse in the center and don’t understand why it’s being drawn.
Thanks.
7 replies
You must log in to post a reply. Not a member yet? Register here!
