import names
def main():
#...
name_view = {"type": "QGraphicsView"}
name_item = {"acceptDrops": "yes", "container": names.Drag and Drop Robot_QGraphicsObject,
"enabled": "yes", "focusable": "no", "movable": "no", "selectable": "no",
"type": "QGraphicsObject", "visible": "yes"}
rect = qgraphicsitem_to_display_coordinates(name_view, name_item)
test.log("%s / %s" % (rect.x, rect.y))
#...
def qgraphicsitem_to_display_coordinates(viewObjectOrName, itemObjectOrName):
class rect:
pass
def get_pos(view, item, point):
scenePos = item.mapToScene(point)
viewportPos = view.mapFromScene(scenePos)
viewPos = view.viewport().mapToParent(viewportPos)
globalViewPos = view.mapToGlobal(QPoint(0, 0))
return globalViewPos.x + viewPos.x, globalViewPos.y + viewPos.y
item = waitForObject(itemObjectOrName)
if className(item) != "QGraphicsItem":
item = object.convertTo(item, "QGraphicsItem")
view = waitForObject(viewObjectOrName)
itemRect = item.boundingRect()
r = rect()
r.x, r.y = get_pos(view, item, itemRect.topLeft())
r.x2, r.y2 = get_pos(view, item, itemRect.bottomRight())
r.width = r.x2 - r.x
r.height = r.y2 - r.y
return r