Координаты достопримечательности без расчета из QGraphicsRectItem

QGraphicsRectItem вставляется в QGraphicsScene, и к этому объекту может быть применено преобразование, что означает перевод и / или вращение.

Есть ли способ, как легко получить координаты (см. Рисунок), даже если объект находится где-нибудь в пространстве?

QGraphicsRectItem:

      class RectItem(QtWidgets.QGraphicsRectItem):

    def paint(self, painter, option, widget=None):
        super(RectItem, self).paint(painter, option, widget)
        painter.save()
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        painter.setPen(QPen(QtGui.QColor(255, 255, 0)))
        self.setFlag(QGraphicsItem.ItemIsSelectable, True)
        painter.drawRect(option.rect)
        painter.restore()

Добавьте предмет:

      def addRect2Scene(self, indx):
    ...
    for i in range(len(mainArray[indx])):

        length = float(leWiArray[indx][i][3])
        width = float(leWiArray[indx][i][4])
        x = int(mainArray[indx][i][1])
        y = int(mainArray[indx][i][2])
        obj = RectItem(QRectF(x - int(length / 2), y - int(width / 2), length, width))
        obj.setPen(QPen(QtGui.QColor(255, 150, 0)))
        ...
        ...
        self.updateTransform(obj, rot, posX, posY, angle)
        self.s.addItem(obj)
        ...

Преобразование:

      def transformObjRect(self,target, rotAlfa, traX, traY, uhelHlPole)
        origin = target.transformOriginPoint()
        transform = QtGui.QTransform().translate(origin.x(), origin.y())
        if rotAlfa is not None:
            if uhelHlPole != 'Alfa':
                if float(uhelHlPole):
                    transform.rotate(-uhelHlPole + (-rotAlfa), Qt.ZAxis)
                else:
                    transform.rotate(-rotAlfa, Qt.ZAxis)
            else:
                transform.rotate(-rotAlfa, Qt.ZAxis)
        else:
            if uhelHlPole != 'Alfa':
                if float(uhelHlPole):
                    transform.rotate(-uhelHlPole, Qt.ZAxis)

        if traX is not None and traY is not None:
            transform.translate(traX, -traY)
        if traX is not None and traY is None:
            transform.translate(traX, 0)
        if traX is None and traY is not None:
            transform.translate(0, -traY)

        transform.translate(-origin.x(), -origin.y())
        target.setTransform(transform)

Цель:

0 ответов

Другие вопросы по тегам