QGraphicView/Scene/RectItem = position incorrect upon reload
Hey
I'm trying to save/load position of my nodes in graphic view but so far they keep showwing up in wrong places...
This is what I do to store them :
Code:
def __init__(self,parent,dict_data):
super(nodes_test,self).__init__(parent)
self.par = parent
self.dict_data = dict_data
def mouseReleaseEvent(self, event):
if len(self.selectedItems()) > 0:
for item in self.selectedItems():
po = item.pos()
print po,item.objectName
self.dict_data[item.objectName]["node_pos"] = po.x(),po.y()
super(nodes_test,self).mouseReleaseEvent(event)
This is what I do to load them :
Code:
load_node.
setRect(QtCore.
QRectF(UI
["node_pos"][0],UI
["node_pos"][1],
300,
250))box_group.setGeometry(2+UI["node_pos"][0],50+UI["node_pos"][1],298,150)
If you can answer in python - great otherwise any sort of answer c++/etc/etc would be great - thanks!
Re: QGraphicView/Scene/RectItem = position incorrect upon reload
Your loading code is obviously incorrect. You save position of a node but while loading you are not setting position of the node but rather its rect or geometry (which is not the same as position). Item's rect corresponds to setting its boundingRect() while item position determines where in the item's parent item (or scene in case it doesn't have a parent item) coordinate system the given item's (0,0) coordinate resides.