[Interest] creating Networks of QGraphicsItems

Rainer Wiesenfarth Rainer_Wiesenfarth at trimble.com
Fri Aug 17 07:31:41 CEST 2012

Am 16.08.2012 23:10, schrieb Philipp Menke:
> [...]
> I subclassed QGraphicItem for the various types of Nodes in such a
> Network (resistors, inductors, capacitors) and for the cables. Having
> two nodes connected with a cable looks good as long as i leave them on
> the position they have been that time.
> The Node-Items are set selectable and movable. When i move a connected
> one, the cable does not get repainted every time.
> [...]
> Every hint/idea is welcome

Ok, as you explicitely welcome _every_ hint, I'll go for mine... ;-)

With the backdrop of making your classes less lightweight than a simple 
QGraphicsItem, you could also inherit your classes from QObject. Then, 
give the cables a slot redraw() and the nodes a signal moved(). Whenever 
a cable is connected to a node, call 
connect(node,SIGNAL(moved()),cable,SLOT(redraw())), whenever a cable is 
disconnected, call disconnect(...) - note the analogy! ;-)

If you consider QObject too heavy, you might re-implement this behavior 
by managing a list of connected cables for each node. Although the other 
direction - the cable stores references to the nodes it connects - would 
be easier (max. two nodes per cable), it won't help you for your problem.

Best Regards / Mit freundlichen Grüßen
Rainer Wiesenfarth

Tel.: +49 (0)711 22 88-10  *  Fax: +49 (0)711 22 88-111
Web: http://www.trimble.com/geospatial/  *  http://www.inpho.de/
Trimble Germany GmbH  *  Branch office Stuttgart
Rotebühlstraße 81  *  70178 Stuttgart  *  Germany
Commercial register: HRB 83893, Darmstadt
Managing Directors: Dr. Frank Heimberg, Hans-Jürgen Gebauer

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4502 bytes
Desc: S/MIME Kryptografische Unterschrift
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120817/f286efdd/attachment.bin>

More information about the Interest mailing list