Results 1 to 2 of 2

Thread: QGraphicView/Scene/RectItem = position incorrect upon reload

  1. #1
    Join Date
    Sep 2013
    Posts
    9
    Thanks
    1
    Qt products

    Default 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 :

    Qt Code:
    1. class nodes_test(QGraphicsScene):
    2. def __init__(self,parent,dict_data):
    3. super(nodes_test,self).__init__(parent)
    4. self.par = parent
    5. self.dict_data = dict_data
    6.  
    7. def mouseReleaseEvent(self, event):
    8. if len(self.selectedItems()) > 0:
    9. for item in self.selectedItems():
    10. po = item.pos()
    11. print po,item.objectName
    12. self.dict_data[item.objectName]["node_pos"] = po.x(),po.y()
    13.  
    14. super(nodes_test,self).mouseReleaseEvent(event)
    To copy to clipboard, switch view to plain text mode 


    This is what I do to load them :

    Qt Code:
    1. load_node.setRect(QtCore.QRectF(UI["node_pos"][0],UI["node_pos"][1],300,250))
    2. box_group.setGeometry(2+UI["node_pos"][0],50+UI["node_pos"][1],298,150)
    To copy to clipboard, switch view to plain text mode 

    If you can answer in python - great otherwise any sort of answer c++/etc/etc would be great - thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Incorrect widget position and size
    By mero in forum Qt Programming
    Replies: 0
    Last Post: 12th April 2011, 03:30
  2. Incorrect position of QPushButton on mac
    By francis in forum Qt Programming
    Replies: 4
    Last Post: 1st March 2011, 17:34
  3. View,Scene and RectItem
    By salmanmanekia in forum Newbie
    Replies: 2
    Last Post: 29th March 2010, 14:31
  4. Cursor Position in scene
    By rogerholmes in forum Newbie
    Replies: 2
    Last Post: 12th March 2010, 15:31
  5. Cursor scene position
    By xgoan in forum Qt Programming
    Replies: 1
    Last Post: 26th December 2006, 13:51

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.