第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

未正確旋轉(zhuǎn)圖像

未正確旋轉(zhuǎn)圖像

慕尼黑的夜晚無繁華 2023-08-03 17:05:56
我正在嘗試旋轉(zhuǎn) QGraphicsView 對象的背景,但遇到了麻煩。紅筆描述了我遇到的問題。我想要的是:我想讓箭頭保持在屏幕中間的中心位置。我希望背景圖像以屏幕中心為參考旋轉(zhuǎn)我想在 QGraphicsView 中定義一個(gè)矩形。這將被定義為界定顯示內(nèi)容的區(qū)域。因此,每次我旋轉(zhuǎn)屏幕時(shí)。圖像“未覆蓋”的區(qū)域始終位于矩形邊界之外。我想在屏幕中間定義旋轉(zhuǎn)參考點(diǎn)(x=VIEW_WIDTH/2,y=VIEW_HEIGHT/2)這是我的代碼:首先,我將顯示箭頭類:from PyQt5 import QtCore, QtGui, QtWidgets # importation of some libraries # Construnction of an arrow item, it'll be used in the QGraphicsView class ArrowItem(QtWidgets.QGraphicsPathItem): # it inherit QgraphicsPathItem, which allows to handle it # in the QgraphicsView    def __init__(self, parent=None): # The init method        super().__init__(parent)        self._length = -1        self._angle = 0        self._points = QtCore.QPointF(), QtCore.QPointF(), QtCore.QPointF() # with three points we # construct a triangle.         self.length = 40.0 # the basic triangle length         self.rotate(180) # the triangle was built upside down, though I've just ran the function 'rotate'    @property    def angle(self):        """        angle of the arrow        :return:        """        return self._angle    @angle.setter    def angle(self, angle):        self._angle = angle    @property    def length(self):        return self._length    @length.setter    def length(self, l):        self._length = l        pos_top = QtCore.QPointF(0, l * 4 / 5)        pos_left = QtCore.QPointF(-l * 3 / 5, -l / 5)        pos_right = QtCore.QPointF(            l * 3 / 5,            -l / 5,        )        path = QtGui.QPainterPath()        path.moveTo(pos_top)        path.lineTo(pos_right)        path.lineTo(pos_left)        self.setPath(path)        self._points = pos_top, pos_left, pos_right    def paint(self, painter, option, widget):        pos_top, pos_left, pos_right = self._points        left_color = QtGui.QColor("#cc0000")        right_color = QtGui.QColor("#ff0000")        bottom_color = QtGui.QColor("#661900")
查看完整描述

1 回答

?
慕姐4208626

TA貢獻(xiàn)1852條經(jīng)驗(yàn) 獲得超7個(gè)贊

如果你想旋轉(zhuǎn)一個(gè)QGraphicsItem,沒有必要使用QTransform,只需使用setRotation方法即可。另一方面,必須對圖像進(jìn)行縮放,以便與可見區(qū)域相交的旋轉(zhuǎn)區(qū)域與可見區(qū)域相同,并且最小區(qū)域計(jì)算如下:sqrt(2) x max(width, height)。綜合以上情況,解決方案是:


from PyQt5 import QtCore, QtGui, QtWidgets



class ArrowItem(QtWidgets.QGraphicsPathItem):

    def __init__(self, parent=None):

        super().__init__(parent)

        self._length = -1

        self._points = (

            QtCore.QPointF(),

            QtCore.QPointF(),

            QtCore.QPointF(),

        )

        self.length = 40.0


    @property

    def length(self):

        return self._length


    @length.setter

    def length(self, l):

        self._length = l


        pos_top = QtCore.QPointF(0, l * 4 / 5)

        pos_left = QtCore.QPointF(-l * 3 / 5, -l / 5)

        pos_right = QtCore.QPointF(

            l * 3 / 5,

            -l / 5,

        )


        path = QtGui.QPainterPath()

        path.moveTo(pos_top)

        path.lineTo(pos_right)

        path.lineTo(pos_left)


        self.setPath(path)


        self._points = pos_top, pos_left, pos_right


    def paint(self, painter, option, widget):

        pos_top, pos_left, pos_right = self._points


        left_color = QtGui.QColor("#cc0000")

        right_color = QtGui.QColor("#ff0000")

        bottom_color = QtGui.QColor("#661900")


        path_left = QtGui.QPainterPath()

        path_left.lineTo(pos_top)

        path_left.lineTo(pos_left)


        path_right = QtGui.QPainterPath()

        path_right.lineTo(pos_top)

        path_right.lineTo(pos_right)


        path_bottom = QtGui.QPainterPath()

        path_bottom.lineTo(pos_left)

        path_bottom.lineTo(pos_right)


        painter.setPen(QtGui.QColor("black"))

        painter.setBrush(left_color)

        painter.drawPath(path_left)

        painter.setBrush(right_color)

        painter.drawPath(path_right)

        painter.setBrush(bottom_color)

        painter.drawPath(path_bottom)


    def moveTo(self, next_position, duration=100):

        self._animation = QtCore.QVariantAnimation()

        self._animation.setStartValue(self.pos())

        self._animation.setEndValue(next_position)

        self._animation.setDuration(duration)

        self._animation.start(QtCore.QAbstractAnimation.DeleteWhenStopped)

        self._animation.valueChanged.connect(self.setPos)



class MainWindow(QtWidgets.QMainWindow):

    VIEW_HEIGHT = 600

    VIEW_WIDTH = 900


    def __init__(self, parent=None):

        super().__init__(parent)


        self.scene = QtWidgets.QGraphicsScene(self)

        self.view = QtWidgets.QGraphicsView(self.scene)

        self.status_btn = QtWidgets.QPushButton("Status")

        self.settings_btn = QtWidgets.QPushButton("Settings")

        self.analyze_btn = QtWidgets.QPushButton("Analyze")

        self.field_btn = QtWidgets.QPushButton("Field")

        self.guide_btn = QtWidgets.QPushButton("Guide")

        self.mapping_btn = QtWidgets.QPushButton("Mapping")


        central_widget = QtWidgets.QWidget()

        self.setCentralWidget(central_widget)


        vlayl = QtWidgets.QVBoxLayout()

        vlayl.addWidget(self.status_btn)

        vlayl.addWidget(self.settings_btn)

        vlayl.addWidget(self.analyze_btn)


        vlayr = QtWidgets.QVBoxLayout()

        vlayr.addWidget(self.field_btn)

        vlayr.addWidget(self.guide_btn)

        vlayr.addWidget(self.mapping_btn)


        hlay = QtWidgets.QHBoxLayout(central_widget)

        hlay.addLayout(vlayl)

        hlay.addWidget(self.view)

        hlay.addLayout(vlayr)


        self.status_btn.clicked.connect(self.rotate_arrow)

        self.guide_btn.clicked.connect(self.rotate_pixmap)


        self.view.setFixedSize(self.VIEW_WIDTH, self.VIEW_HEIGHT)

        r = self.view.mapToScene(self.view.viewport().rect()).boundingRect()

        self.view.setSceneRect(r)


        factor = 1.5 * max(self.VIEW_WIDTH, self.VIEW_HEIGHT)

        pixmap = QtGui.QPixmap("ola.png").scaled(factor, factor)

        self.pixmap_item = self.scene.addPixmap(pixmap)

        center = self.pixmap_item.boundingRect().center()

        self.pixmap_item.setPos(-center)

        self.pixmap_item.setTransformOriginPoint(center)


        self.arrow_item = ArrowItem()

        self.scene.addItem(self.arrow_item)


    def rotate_arrow(self):

        delta = 30.0

        self.arrow_item.setRotation(self.arrow_item.rotation() + delta)


    def rotate_pixmap(self):

        delta = 15.0


        self.pixmap_item.setRotation(self.pixmap_item.rotation() + delta)

        self.arrow_item.setRotation(self.arrow_item.rotation() + delta)



if __name__ == "__main__":

    import sys


    app = QtWidgets.QApplication(sys.argv)

    w = MainWindow()

    w.show()

    sys.exit(app.exec_())


查看完整回答
反對 回復(fù) 2023-08-03
  • 1 回答
  • 0 關(guān)注
  • 141 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號