diff --git a/beeref/items.py b/beeref/items.py index 7ad44b4..0a71246 100644 --- a/beeref/items.py +++ b/beeref/items.py @@ -43,8 +43,7 @@ class BeePixmapItem(SelectableMixin, QtWidgets.QGraphicsPixmapItem): def set_pos_center(self, pos): """Sets the position using the item's center as the origin point.""" - center = self.mapToScene(QtCore.QPointF(self.width/2, self.height/2)) - self.setPos(pos - center) + self.setPos(pos - self.center_scene_coords) @property def width(self): diff --git a/tests/test_items.py b/tests/test_items.py index 6fa5150..5aa7897 100644 --- a/tests/test_items.py +++ b/tests/test_items.py @@ -33,6 +33,17 @@ class BeePixmapItemTestCase(BeeTestCase): assert item.pos().x() == -100 assert item.pos().y() == -50 + def test_set_pos_center_when_scaled(self): + item = BeePixmapItem(QtGui.QImage()) + item.setScale(2) + with patch('beeref.items.BeePixmapItem.width', + new_callable=PropertyMock, return_value=200): + with patch('beeref.items.BeePixmapItem.height', + new_callable=PropertyMock, return_value=100): + item.set_pos_center(QtCore.QPointF(0, 0)) + assert item.pos().x() == -200 + assert item.pos().y() == -100 + def test_pixmap_to_bytes(self): item = BeePixmapItem(QtGui.QImage(self.imgfilename3x3)) assert item.pixmap_to_bytes().startswith(b'\x89PNG')