def labelTransformation(self, pos, size): transform = QTransform() transform.translate(pos.x(), pos.y()) transform.rotate(self.labelRotation()) flags = self.labelAlignment() if flags == 0: flags = self.Flags[self.alignment()] if flags & Qt.AlignLeft: x = -size.width() elif flags & Qt.AlignRight: x = 0. else: x = -(.5 * size.width()) if flags & Qt.AlignTop: y = -size.height() elif flags & Qt.AlignBottom: y = 0 else: y = -(.5 * size.height()) transform.translate(x, y) return transform
def labelTransformation(self, pos, size): transform = QTransform() transform.translate(pos.x(), pos.y()) transform.rotate(self.labelRotation()) flags = self.labelAlignment() if flags == 0: flags = self.Flags[self.alignment()] if flags & Qt.AlignLeft: x = -size.width() elif flags & Qt.AlignRight: x = 0. else: x = -(.5*size.width()) if flags & Qt.AlignTop: y = -size.height() elif flags & Qt.AlignBottom: y = 0 else: y = -(.5*size.height()) transform.translate(x, y) return transform
def labelTransformation(self, pos, size): """ Calculate the transformation that is needed to paint a label depending on its alignment and rotation. :param QPointF pos: Position where to paint the label :param QSizeF size: Size of the label :return: Transformation matrix .. seealso:: :py:meth:`setLabelAlignment()`, :py:meth:`setLabelRotation()` """ transform = QTransform() transform.translate(pos.x(), pos.y()) transform.rotate(self.labelRotation()) flags = self.labelAlignment() if flags == 0: flags = self.Flags[self.alignment()] if flags & Qt.AlignLeft: x = -size.width() elif flags & Qt.AlignRight: x = 0. else: x = -(.5*size.width()) if flags & Qt.AlignTop: y = -size.height() elif flags & Qt.AlignBottom: y = 0 else: y = -(.5*size.height()) transform.translate(x, y) return transform