1 Attachment(s)
QGraphicsItem or QGraphicsProxyWidget?
Hi,
I need to create an image as below
Attachment 3604
It contains:
1) one or more nodes with a text label. The node is not filled when created, but will be filled with progress
2) there are one or more ports on each node connecting them together
I first looked at the Diagram Scene example, but I'll need the port(s) to know which node connecting to which port and also need to add text to the node.
Should I subclass QGraphicsItem or QGraphicsProxyWidget or something else? Thanks in advance.
Re: QGraphicsItem or QGraphicsProxyWidget?
Definitely not proxy widget. I'd subclass QGraphicsRectItem or QGraphicsTextItem or even compose the item from one rect item, one text item and a couple of ellipse items (or others) for the ports.
Re: QGraphicsItem or QGraphicsProxyWidget?
Thanks. I understood sub-class QGraphicsRectItem and QGraphicsTextItem. What do you mean by "compose the item from one rect item, one text item and a couple of ellipse items (or others) for the ports"? Have a class that contains a QGraphicsRectItem, QGraphicsTextItem, and ports? What will my paint method look like?
Re: QGraphicsItem or QGraphicsProxyWidget?
Quote:
Originally Posted by
ttvo
What will my paint method look like?
You won't have one.
Code:
portN->setPos(0, -25);
portS->setPos(0, 25);
scene.addItem(rect);
v.setScene(&scene);
v.show();
Re: QGraphicsItem or QGraphicsProxyWidget?
Great, that works. I decided to subclass QGraphicsTextItem to include the draw of its boundary, eliminating the need for the QGraphicsRectItem *rect. So the ports are children of my custom text, but how am I going to be able to query how many ports a given custom text item has?
Should I make the ports as member variable of my custom text? If so, will I need to override the paint method to draw the ports (of type QGraphicsEllipseItem or QGraphicsRectItem). Thanks.
Re: QGraphicsItem or QGraphicsProxyWidget?
Quote:
Originally Posted by
ttvo
Great, that works. I decided to subclass QGraphicsTextItem to include the draw of its boundary, eliminating the need for the QGraphicsRectItem *rect. So the ports are children of my custom text, but how am I going to be able to query how many ports a given custom text item has?
You need to provide some API for this in your subclass.
Quote:
Should I make the ports as member variable of my custom text? If so, will I need to override the paint method to draw the ports (of type QGraphicsEllipseItem or QGraphicsRectItem). Thanks.
Why does informing one object about a state of another object require reimplementing its drawing routines?