我正在尝试旋转 QGraphicsView 对象的背景,但遇到了麻烦。红笔描述了我遇到的问题。
我想要的是:
我想让箭头保持在屏幕中间的中心位置。
我希望背景图像以屏幕中心为参考旋转
我想在 QGraphicsView 中定义一个矩形。这将被定义为界定显示内容的区域。因此,每次我旋转屏幕时。图像“未覆盖”的区域始终位于矩形边界之外。
我想在屏幕中间定义旋转参考点(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")
慕姐4208626
相关分类