本文整理汇总了Python中PyQt5.QtGui.QTransform.rotate方法的典型用法代码示例。如果您正苦于以下问题:Python QTransform.rotate方法的具体用法?Python QTransform.rotate怎么用?Python QTransform.rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QTransform
的用法示例。
在下文中一共展示了QTransform.rotate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _image
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import rotate [as 别名]
def _image(file, sub_folder, rotate=None):
pixmap = QPixmap(os_path_join(_BASE_PATH, sub_folder, file))
if rotate is None:
return pixmap
transform = QTransform()
transform.rotate(rotate)
return pixmap.transformed(transform)
示例2: wind_icon_direction
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import rotate [as 别名]
def wind_icon_direction(self):
transf = QTransform()
angle = self.weatherdata['Wind'][2]
logging.debug('Wind degrees direction: ' + angle)
transf.rotate(int(float(angle)))
rotated = self.wind_icon.transformed(transf, mode=Qt.SmoothTransformation)
self.wind_icon_label.setPixmap(rotated)
示例3: _plat_get_blocks
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import rotate [as 别名]
def _plat_get_blocks(self, block_count_per_side, orientation):
image = QImage(str(self.path))
image = image.convertToFormat(QImage.Format_RGB888)
# MYSTERY TO SOLVE: For reasons I cannot explain, orientations 5 and 7 don't work for
# duplicate scanning. The transforms seems to work fine (if I try to save the image after
# the transform, we see that the image has been correctly flipped and rotated), but the
# analysis part yields wrong blocks. I spent enought time with this feature, so I'll leave
# like that for now. (by the way, orientations 5 and 7 work fine under Cocoa)
if 2 <= orientation <= 8:
t = QTransform()
if orientation == 2:
t.scale(-1, 1)
elif orientation == 3:
t.rotate(180)
elif orientation == 4:
t.scale(1, -1)
elif orientation == 5:
t.scale(-1, 1)
t.rotate(90)
elif orientation == 6:
t.rotate(90)
elif orientation == 7:
t.scale(-1, 1)
t.rotate(270)
elif orientation == 8:
t.rotate(270)
image = image.transformed(t)
return getblocks(image, block_count_per_side)
示例4: setHeading
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import rotate [as 别名]
def setHeading(self, heading):
xForm = QTransform()
xForm.translate(self.__center_x, self.__center_y)
xForm.rotate(math.degrees(heading))
xForm.translate(-self.__center_x, -self.__center_y)
self.setTransform(xForm)
self.mapTextureBasedOnZoom(self.brush())
示例5: rotate
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import rotate [as 别名]
def rotate(self):
t = QTransform()
# for x in range (0, 150):
t.rotate(-1)
self.label.setPixmap(self.label.pixmap().transformed(t))
print("FINISHED")
示例6: visibleIn
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import rotate [as 别名]
def visibleIn(area, object, renderer):
boundingRect = renderer.boundingRect(object)
if (object.rotation() != 0):
# Rotate around object position
pos = renderer.pixelToScreenCoords_(object.position())
boundingRect.translate(-pos)
transform = QTransform()
transform.rotate(object.rotation())
boundingRect = transform.mapRect(boundingRect)
boundingRect.translate(pos)
return intersects(area, boundingRect)
示例7: _updateSequenceText
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import rotate [as 别名]
def _updateSequenceText(self):
seq_item = self._seq_item
is_on_top = self._is_on_top
index = self._insertion.idx()
base_text = self._seq_text
font = styles.SEQUENCEFONT
seq_font_h = styles.SEQUENCEFONTH
insert_w = styles.INSERTWIDTH
seq_font_char_w = styles.SEQUENCEFONTCHARWIDTH
# draw sequence on the insert
if base_text: # only draw sequences if they exist i.e. not None!
len_BT = len(base_text)
if is_on_top:
angle_offset = 0
else:
angle_offset = 180
if len_BT > 20:
base_text = base_text[:17] + '...'
len_BT = len(base_text)
fraction_arc_len_per_char = (1.0 - 2.0*_FRACTION_INSERT_TO_PAD) / (len_BT + 1)
seq_item.setPen(QPen(Qt.NoPen))
seq_item.setBrush(QBrush(Qt.black))
seq_path = QPainterPath()
loop_path = self.path()
for i in range(len_BT):
frac = _FRACTION_INSERT_TO_PAD + (i+1)*fraction_arc_len_per_char
pt = loop_path.pointAtPercent(frac)
tang_ang = loop_path.angleAtPercent(frac)
temp_path = QPainterPath()
# 1. draw the text
temp_path.addText(0, 0, font, base_text[i if is_on_top else -i-1])
# 2. center it at the zero point different for top and bottom
# strands
if not is_on_top:
temp_path.translate(0, -seq_font_h - insert_w)
temp_path.translate(QPointF(-seq_font_char_w / 2.,
-2 if is_on_top else seq_font_h))
mat = QTransform()
# 3. rotate it
mat.rotate(-tang_ang + angle_offset)
rotated_path = mat.map(temp_path)
# 4. translate the rotate object to it's position on the part
rotated_path.translate(pt)
seq_path.addPath(rotated_path)
# end for
seq_item.setPath(seq_path)
示例8: rotatePlayer
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import rotate [as 别名]
def rotatePlayer(self, direction):
"""
Function responsible for rotating players icon.
"""
rotation = QTransform()
if direction == 'up':
rotation.rotate(0)
elif direction == 'right':
rotation.rotate(90)
elif direction == 'down':
rotation.rotate(180)
elif direction == 'left':
rotation.rotate(270)
self.use_this_pixmap = \
self.nurse_pixmap_base.transformed(rotation)
self.nurse_pixmap = \
self.nurse_pixmap_base.transformed(rotation)
self.nurse_left_pixmap = \
self.nurse_left_pixmap_base.transformed(rotation)
self.nurse_right_pixmap = \
self.nurse_right_pixmap_base.transformed(rotation)
"""
示例9: loadImage
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import rotate [as 别名]
def loadImage(self):
self.newImg = QImage()
self.newImg.load(self.photoFileManager.getCurPhotoFilename())
self.newImgInfo = self.photoFileManager.getCurPhotoInfo()
transform = QTransform()
transform.rotate(self.newImgInfo.rotationAngle)
self.interImg = self.newImg.transformed(transform, Qt.SmoothTransformation)
# xReqdSize = self.cellSize.width() * xFactor + self.xBetweenPics * (xFactor-1)
# yReqdSize = self.cellSize.height() * yFactor + self.yBetweenPics * (yFactor-1)
self.inter2Img = self.interImg.scaled(QSize(self.width(),self.height()),
Qt.KeepAspectRatio, Qt.SmoothTransformation)
# finalImg = interImg.copy(0,0,xReqdSize,yReqdSize)
# print("XY Size", xFactor, yFactor, xReqdSize,yReqdSize)
return self.inter2Img, self.newImgInfo
示例10: mouseMoveEvent
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import rotate [as 别名]
def mouseMoveEvent(self, event):
if self.__dragActive:
mousePos = self.view.mapToScene(self.view.mapFromGlobal(QCursor.pos()))
vec1 = QVector2D(mousePos)
vec1.normalize()
trans = QTransform()
trans.rotate(self.rotation())
vec2 = QVector2D(self.p2 * trans)
vec2.normalize()
angle = math.acos(max(-1, min(1, QVector2D.dotProduct(vec1, vec2)))) * 180 / math.pi
# clockwise rotation
if vec1.y() * vec2.x() < vec1.x() * vec2.y():
angle *= -1
angle = (self.rotation() + angle) % 360
self.setRotation(angle)
示例11: paint
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import rotate [as 别名]
def paint(self, qp: QPainter, option: QStyleOptionGraphicsItem, widget: QWidget=None):
p = self.parentItem()
pRot = p.rotation()
trans = QTransform()
trans.rotate(-p.rotation())
p2Scene = p.mapToScene(p.p2)
if 0 <= pRot < 90:
trans.translate(p2Scene.x() - self.boundingRect().width(), p2Scene.y())
elif 90 <= pRot < 180:
trans.translate(p2Scene.x(), p2Scene.y())
elif 180 <= pRot < 270:
trans.translate(p2Scene.x(), p2Scene.y() - self.boundingRect().height())
elif 270 <= 360:
trans.translate(p2Scene.x() - self.boundingRect().width(), p2Scene.y() - self.boundingRect().height())
self.setTransform(trans)
super().paint(qp, option, widget)
示例12: _createPreXoverPainterPath
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import rotate [as 别名]
def _createPreXoverPainterPath( elements: List[List[QPointF]],
end_poly: QPolygonF = None,
is_fwd: bool = True) -> QPainterPath:
path = QPainterPath()
next_pt = None
for element in elements:
start_pt = element[0]
path.moveTo(start_pt)
for next_pt in element[1:]:
path.lineTo(next_pt)
if end_poly is not None:
h = end_poly.boundingRect().height()/2
xoffset = -h if is_fwd else h
w = end_poly.boundingRect().width()
yoffset = w if is_fwd else -w
angle = -90 if is_fwd else 90
T = QTransform()
T.translate(next_pt.x()+xoffset, next_pt.y()+yoffset)
T.rotate(angle)
path.addPolygon(T.map(end_poly))
return path
示例13: rotate_image
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import rotate [as 别名]
def rotate_image(self, rotation):
if self.original_image is not None:
print(rotation)
# Rotate the original and viewable image to ensure a constant workflow when modifying from canvas
matrix = QTransform()
matrix.translate(self.image.width() / 2, self.image.height() / 2)
matrix.rotate(rotation)
matrix.translate(-self.image.width() / 2, -self.image.height() / 2)
# Save transformed image
self.image = self.image.transformed(matrix)
original_matrix = QTransform()
original_matrix.translate(self.original_image.width() / 2, self.original_image.height() / 2)
original_matrix.rotate(rotation)
original_matrix.translate(-self.original_image.width() / 2, -self.original_image.height() / 2)
# Save transformed image
self.original_image = self.original_image.transformed(original_matrix)
self.scene.clear()
self.scene.addItem(CustomQGraphicsPixmapItem(QPixmap.fromImage(self.image), self.c_width, self.c_height))
self.scene.update()
示例14: syncWithMapObject
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import rotate [as 别名]
def syncWithMapObject(self, renderer):
nameVisible = self.mObject.isVisible() and self.mObject.name()!=''
self.setVisible(nameVisible)
if (not nameVisible):
return
metrics = QFontMetricsF(QGuiApplication.font())
boundingRect = metrics.boundingRect(self.mObject.name())
boundingRect.translate(-boundingRect.width() / 2, -labelDistance)
boundingRect.adjust(-labelMargin*2, -labelMargin, labelMargin*2, labelMargin)
pixelPos = renderer.pixelToScreenCoords_(self.mObject.position())
bounds = objectBounds(self.mObject, renderer)
# Adjust the bounding box for object rotation
transform = QTransform()
transform.translate(pixelPos.x(), pixelPos.y())
transform.rotate(self.mObject.rotation())
transform.translate(-pixelPos.x(), -pixelPos.y())
bounds = transform.mapRect(bounds)
# Center the object name on the object bounding box
pos = QPointF((bounds.left() + bounds.right()) / 2, bounds.top())
self.setPos(pos + self.mObject.objectGroup().offset())
if (self.mBoundingRect != boundingRect):
self.prepareGeometryChange()
self.mBoundingRect = boundingRect
示例15: drawObjects
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import rotate [as 别名]
def drawObjects(self, painter):
"""
Drawing objects like bed or curtain on map.
"""
# reminder:
# obj = [(pos_x, pos_y), (width, height), PIXMAP, ROTATION_ANGLE]
for obj in self.objects:
if obj.getAngle() != 0:
rotation = QTransform()
rotation.rotate(obj.getAngle())
pixmap = self.pixmaps[obj.getPixmap()].transformed(rotation)
else:
pixmap = self.pixmaps[obj.getPixmap()]
state = obj.getState()
painter.drawPixmap(
state[0], # pos_x
state[1], # pos_y
state[2], # width
state[3], # height
pixmap
)
# Drawing path - delete when not needed
for (x, y) in self.path:
painter.setPen(Qt.red)
painter.drawRect(x * 80, y * 80, 80, 80)
self.fillRealBoard(
state[0], # pos_x
state[1], # pos_y
state[2], # width
state[3], # height
obj.getName()
)