I am trying to convert pygraphviz node/edge coordinates to PyQt4
qgraphicsTextItem, but not success.
I read some blog and it was clear said the pygraphviz nodes are to be
represented by QGraphicsEllipseItem objects
which I did and its perfect one to one match, I mean graphviz layout
and QgraphicsEllipseitem were matched (node and edge were connected at
the right place in pyqt).
I did
G = pygraphviz.AGraph ()
G.add_node(
item.id,label=item.'name',style='filled',fontname='Helvetica',fontsize=9)
G.add_edge(
src.name,
des.name,color='blue')
G.layout(prog='dot')
For transformation to pyqt4, qgraphicsitem I used
x = node.attr[pos][0]
y = node.attr[pos][1]
width = node.attr[width] *72 (for dpi)
height =node.attr[height] *72 (for dpi)
pItem = QGraphicsEllispeitem(item)
pItem.setRect(x-w/2.0,y-h/2.0,w,h) (x-w/2 and y-h/2 because x and y co-
ordinates are center of the node and to get topleft)
This a perfect match node and edges are connected in pyqt4 as compared
to pygraphviz.
I added shape='box' to node attributes and got x,y,w,h as showned
before but instead of GraphicsEllispeitem I replaced QgraphicsTextItem
at this points, I have set background for qgraphicTextitem which gives
a background box on the Textitem
pItem = QGraphicsTextitem(item)
pItem.setPos(x-w/2.0,y-h/2.0)
But there is difference when compared to pygraphviz to pyqt4, this
may be because qgraphicsTextitem, width depends on text. Is there a
way to correct this difference or I am doing something wrong?
Thank you in advance