本文整理汇总了Python中PyQt5.QtGui.QTransform.fromScale方法的典型用法代码示例。如果您正苦于以下问题:Python QTransform.fromScale方法的具体用法?Python QTransform.fromScale怎么用?Python QTransform.fromScale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QTransform
的用法示例。
在下文中一共展示了QTransform.fromScale方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import fromScale [as 别名]
def init (self):
self.m_scaleX = self.width() / self.m_originalWidth
self.m_scaleY = self.height() / self.m_originalHeight
self.m_itemHand = QGraphicsSvgItem(":/qfi/images/vsi/vsi_hand.svg")
self.m_itemHand.setCacheMode (QGraphicsItem.NoCache)
self.m_itemHand.setZValue( self.m_handZ )
self.m_itemHand.setTransform( QTransform.fromScale( self.m_scaleX, self.m_scaleY ), True )
self.m_itemHand.setTransformOriginPoint( self.m_originalVsiCtr )
self.m_scene.addItem (self.m_itemHand)
self.m_itemFace = QGraphicsSvgItem(":/qfi/images/vsi/vsi_face.svg")
self.m_itemFace.setCacheMode (QGraphicsItem.NoCache)
self.m_itemFace.setZValue( self.m_faceZ )
self.m_itemFace.setTransform( QTransform.fromScale( self.m_scaleX, self.m_scaleY ), True )
self.m_itemFace.setTransformOriginPoint( self.m_originalVsiCtr )
self.m_scene.addItem (self.m_itemFace)
self.m_itemCase = QGraphicsSvgItem(":/qfi/images/vsi/vsi_case.svg")
self.m_itemCase.setCacheMode (QGraphicsItem.NoCache)
self.m_itemCase.setZValue( self.m_caseZ )
self.m_itemCase.setTransform( QTransform.fromScale( self.m_scaleX, self.m_scaleY ), True )
self.m_itemCase.setTransformOriginPoint( self.m_originalVsiCtr )
self.m_scene.addItem (self.m_itemCase)
self.centerOn (self.width()/2, self.height()/2)
self.updateView()
示例2: draw_frequency_marker
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import fromScale [as 别名]
def draw_frequency_marker(self, x_pos, frequency):
if frequency is None:
self.clear_frequency_marker()
return
y1 = self.sceneRect().y()
y2 = self.sceneRect().y() + self.sceneRect().height()
if self.frequency_marker is None:
pen = QPen(constants.LINECOLOR, 0)
self.frequency_marker = [None, None]
self.frequency_marker[0] = self.addLine(x_pos, y1, x_pos, y2, pen)
self.frequency_marker[1] = self.addSimpleText("")
self.frequency_marker[1].setBrush(QBrush(constants.LINECOLOR))
font = QFont()
font.setBold(True)
font.setPointSize(int(font.pointSize() * 1.25)+1)
self.frequency_marker[1].setFont(font)
self.frequency_marker[0].setLine(x_pos, y1, x_pos, y2)
scale_x, scale_y = self.__calc_x_y_scale(self.sceneRect())
self.frequency_marker[1].setTransform(QTransform.fromScale(scale_x, scale_y), False)
self.frequency_marker[1].setText("Tune to " + Formatter.big_value_with_suffix(frequency, decimals=3))
font_metric = QFontMetrics(self.frequency_marker[1].font())
text_width = font_metric.width("Tune to") * scale_x
text_width += (font_metric.width(" ") * scale_x) / 2
self.frequency_marker[1].setPos(x_pos-text_width, 0.95*y1)
示例3: ParseTransformAttrib
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import fromScale [as 别名]
def ParseTransformAttrib(s):
# where s is an SVG transform attribute such as "translate(-2,1) matrix(0 1 2 3 4 5)"
# return a list of QTransforms
xforms = []
s = s.lower()
while s:
s = re.sub(r'^\s+,?\s+', '', s) # remove leading WS,WS
m = re.match(r'\s*(\w+)\s*\(((\s*[0-9e.+-]+\s*,?)+)\)', s) # match identifier(numbers) clause
if m:
values = SplitFloatValues(m.group(2))
if m.group(1) == 'translate':
if len(values) == 1: values.append(0)
xforms.append( QTransform.fromTranslate(*values) )
elif m.group(1) == 'scale':
if len(values) == 1: values.append(values[0])
xforms.append( QTransform.fromScale(*values) )
elif m.group(1) == 'rotate':
xforms.append( QTransform().rotate(values[0]) ) # TODO: handle cx,cy values
elif m.group(1) == 'matrix':
logger.trace('matrix({}): m.group(2) = {}', values, m.group(2))
xforms.append( QTransform( values[0], values[1], 0
, values[2], values[3], 0
, values[4], values[5], 1) )
# TODO: handle skewX and skewY
else: logger.warning('unrecognized transform: {}', m.group())
s = s[m.end()+1:]
else:
if s: logger.warning('unparsed transform: {}', s)
break
return xforms
示例4: new_absolute_zoom
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import fromScale [as 别名]
def new_absolute_zoom(self, factor):
"""Sets a new absolute zoom and emits viewport_changed.
"""
f = factor
scene_rect = self.scene().sceneRect() # Scene
view_rect = self.viewport().rect() # Available space
# The size of the scene if the new transform is applied
t_scene_rect = QTransform.fromScale(f, f).mapRect(scene_rect)
if (t_scene_rect.width() < view_rect.width() and
t_scene_rect.height() < view_rect.height()):
# The user wants to zoom out so that the image is smaller than the
# view
self.zoom_home()
else:
f = min(self.MAXIMUM_ZOOM, f)
msg = 'Change absolute zoom from [{0}] to [{1}]'
debug_print(msg.format(self.absolute_zoom, f))
selected = self.scene().selectedItems()
if not selected:
# No selection so we want to centre on the mouse cursor, if it
# is within the view. We need to get the mouse position in
# scene coords before applying the zoom.
mouse_pos = self.mapFromGlobal(QCursor.pos())
if self.rect().contains(mouse_pos, proper=True):
mouse_pos = self.mapToScene(mouse_pos)
else:
mouse_pos = None
self.setTransform(QTransform.fromScale(f, f))
if selected:
# Centre on selected items
self.centerOn(
unite_rects(i.sceneBoundingRect() for i in selected).center()
)
elif mouse_pos:
# Centre on mouse position
self.centerOn(mouse_pos)
else:
# Default behaviour is fine
pass
self.viewport_changed.emit(self.normalised_scene_rect())
示例5: _QGraphicssItem_scale
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import fromScale [as 别名]
def _QGraphicssItem_scale(self, *args):
if args:
warnings.warn(
"QGraphicsItem.scale(sx, sy) is obsolete and removed in PyQt5. "
"Use setTransform(QTransform.fromScale(sx, sy), True) instead.",
DeprecationWarning,
stacklevel=2
)
self.setTransform(QTransform.fromScale(*args), True)
else:
return _QGraphicsItem_scale1(self)
示例6: init
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import fromScale [as 别名]
def init (self):
self.m_scaleX = self.width() / self.m_originalWidth
self.m_scaleY = self.height() / self.m_originalHeight
self.m_itemBack = QGraphicsSvgItem(":/qfi/images/adi/adi_back.svg")
self.m_itemBack.setCacheMode (QGraphicsItem.NoCache)
self.m_itemBack.setZValue( self.m_backZ )
self.m_itemBack.setTransform( QTransform.fromScale( self.m_scaleX, self.m_scaleY ), True )
self.m_itemBack.setTransformOriginPoint( self.m_originalAdiCtr )
self.m_scene.addItem (self.m_itemBack)
self.m_itemFace = QGraphicsSvgItem(":/qfi/images/adi/adi_face.svg")
self.m_itemFace.setCacheMode (QGraphicsItem.NoCache)
self.m_itemFace.setZValue( self.m_faceZ )
self.m_itemFace.setTransform( QTransform.fromScale( self.m_scaleX, self.m_scaleY ), True )
self.m_itemFace.setTransformOriginPoint( self.m_originalAdiCtr )
self.m_scene.addItem (self.m_itemFace)
self.m_itemRing = QGraphicsSvgItem(":/qfi/images/adi/adi_ring.svg")
self.m_itemRing.setCacheMode (QGraphicsItem.NoCache)
self.m_itemRing.setZValue( self.m_ringZ )
self.m_itemRing.setTransform( QTransform.fromScale( self.m_scaleX, self.m_scaleY ), True )
self.m_itemRing.setTransformOriginPoint( self.m_originalAdiCtr )
self.m_scene.addItem (self.m_itemRing)
self.m_itemCase = QGraphicsSvgItem(":/qfi/images/alt/alt_case.svg")
self.m_itemCase.setCacheMode (QGraphicsItem.NoCache)
self.m_itemCase.setZValue( self.m_caseZ )
self.m_itemCase.setTransform( QTransform.fromScale( self.m_scaleX, self.m_scaleY ), True )
self.m_itemCase.setTransformOriginPoint( self.m_originalAdiCtr )
self.m_scene.addItem (self.m_itemCase)
self.centerOn (self.width()/2, self.height()/2)
self.updateView()
示例7: init
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import fromScale [as 别名]
def init (self):
self.m_scaleX = self.width() / self.m_originalWidth
self.m_scaleY = self.height() / self.m_originalHeight
self.m_itemFace_1 = QGraphicsSvgItem(":/qfi/images/alt/alt_face_1.svg")
self.m_itemFace_1.setCacheMode (QGraphicsItem.NoCache)
self.m_itemFace_1.setZValue( self.m_face1Z )
self.m_itemFace_1.setTransform( QTransform.fromScale( self.m_scaleX, self.m_scaleY ), True )
self.m_itemFace_1.setTransformOriginPoint( self.m_originalAltCtr )
self.m_scene.addItem (self.m_itemFace_1)
self.m_itemFace_2 = QGraphicsSvgItem(":/qfi/images/alt/alt_face_2.svg")
self.m_itemFace_2.setCacheMode (QGraphicsItem.NoCache)
self.m_itemFace_2.setZValue( self.m_face2Z )
self.m_itemFace_2.setTransform( QTransform.fromScale( self.m_scaleX, self.m_scaleY ), True )
self.m_itemFace_2.setTransformOriginPoint( self.m_originalAltCtr )
self.m_scene.addItem (self.m_itemFace_2)
self.m_itemFace_3 = QGraphicsSvgItem(":/qfi/images/alt/alt_face_3.svg")
self.m_itemFace_3.setCacheMode (QGraphicsItem.NoCache)
self.m_itemFace_3.setZValue( self.m_face3Z )
self.m_itemFace_3.setTransform( QTransform.fromScale( self.m_scaleX, self.m_scaleY ), True )
self.m_itemFace_3.setTransformOriginPoint( self.m_originalAltCtr )
self.m_scene.addItem (self.m_itemFace_3)
self.m_itemHand_1 = QGraphicsSvgItem(":/qfi/images/alt/alt_hand_1.svg")
self.m_itemHand_1.setCacheMode (QGraphicsItem.NoCache)
self.m_itemHand_1.setZValue( self.m_hand1Z )
self.m_itemHand_1.setTransform( QTransform.fromScale( self.m_scaleX, self.m_scaleY ), True )
self.m_itemHand_1.setTransformOriginPoint( self.m_originalAltCtr )
self.m_scene.addItem (self.m_itemHand_1)
self.m_itemHand_2 = QGraphicsSvgItem(":/qfi/images/alt/alt_hand_2.svg")
self.m_itemHand_2.setCacheMode (QGraphicsItem.NoCache)
self.m_itemHand_2.setZValue( self.m_hand2Z )
self.m_itemHand_2.setTransform( QTransform.fromScale( self.m_scaleX, self.m_scaleY ), True )
self.m_itemHand_2.setTransformOriginPoint( self.m_originalAltCtr )
self.m_scene.addItem (self.m_itemHand_2)
self.m_itemCase = QGraphicsSvgItem(":/qfi/images/alt/alt_case.svg")
self.m_itemCase.setCacheMode (QGraphicsItem.NoCache)
self.m_itemCase.setZValue( self.m_caseZ )
self.m_itemCase.setTransform( QTransform.fromScale( self.m_scaleX, self.m_scaleY ), True )
self.m_itemCase.setTransformOriginPoint( self.m_originalAltCtr )
self.m_scene.addItem (self.m_itemCase)
self.centerOn (self.width()/2, self.height()/2)
self.updateView()
示例8: QApplication
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import fromScale [as 别名]
if __name__ == "__main__":
import sys
import math
app = QApplication(sys.argv)
qsrand(QTime(0, 0, 0).secsTo(QTime.currentTime()))
scene = QGraphicsScene(-200, -200, 400, 400)
for i in range(10):
item = ColorItem()
angle = i * 6.28 / 10.0
item.setPos(math.sin(angle) * 150, math.cos(angle) * 150)
scene.addItem(item)
robot = Robot()
robot.setTransform(QTransform.fromScale(1.2, 1.2), True)
robot.setPos(0, -20)
scene.addItem(robot)
view = GraphicsView(scene)
view.setRenderHint(QPainter.Antialiasing)
view.setViewportUpdateMode(QGraphicsView.BoundingRectViewportUpdate)
view.setBackgroundBrush(QColor(230, 200, 167))
view.setWindowTitle("Drag and Drop Robot")
view.show()
sys.exit(app.exec_())
示例9: adjustScale
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import fromScale [as 别名]
def adjustScale(self, scale):
self.setTransform(QTransform.fromScale(scale, scale))
self.setRenderHint(QPainter.SmoothPixmapTransform, self.mZoomable.smoothTransform())
示例10: renderMapToImage
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import fromScale [as 别名]
def renderMapToImage(self):
if (not self.mMapDocument):
self.mMapImage = QImage()
return
renderer = self.mMapDocument.renderer()
r = self.contentsRect()
mapSize = renderer.mapSize()
if (mapSize.isEmpty()):
self.mMapImage = QImage()
return
margins = self.mMapDocument.map().computeLayerOffsetMargins()
mapSize.setWidth(mapSize.width() + margins.left() + margins.right())
mapSize.setHeight(mapSize.height() + margins.top() + margins.bottom())
# Determine the largest possible scale
scale = min( r.width() / mapSize.width(), r.height() / mapSize.height())
# Allocate a new image when the size changed
imageSize = mapSize * scale
if (self.mMapImage.size() != imageSize):
self.mMapImage = QImage(imageSize, QImage.Format_ARGB32_Premultiplied)
self.updateImageRect()
if (imageSize.isEmpty()):
return
drawObjects = bool(self.mRenderFlags & MiniMapRenderFlag.DrawObjects)
drawTiles = bool(self.mRenderFlags & MiniMapRenderFlag.DrawTiles)
drawImages = bool(self.mRenderFlags & MiniMapRenderFlag.DrawImages)
drawTileGrid = bool(self.mRenderFlags & MiniMapRenderFlag.DrawGrid)
visibleLayersOnly = bool(self.mRenderFlags & MiniMapRenderFlag.IgnoreInvisibleLayer)
# Remember the current render flags
renderFlags = renderer.flags()
renderer.setFlag(RenderFlag.ShowTileObjectOutlines, False)
self.mMapImage.fill(Qt.transparent)
painter = QPainter(self.mMapImage)
painter.setRenderHints(QPainter.SmoothPixmapTransform)
painter.setTransform(QTransform.fromScale(scale, scale))
painter.translate(margins.left(), margins.top())
renderer.setPainterScale(scale)
for layer in self.mMapDocument.map().layers():
if (visibleLayersOnly and not layer.isVisible()):
continue
painter.setOpacity(layer.opacity())
painter.translate(layer.offset())
tileLayer = layer
objGroup = layer
imageLayer = layer
tp = type(layer)
if (tp==TileLayer and drawTiles):
renderer.drawTileLayer(painter, tileLayer)
elif (tp==ObjectGroup and drawObjects):
objects = objGroup.objects()
if (objGroup.drawOrder() == ObjectGroup.DrawOrder.TopDownOrder):
objects = QList(sorted(objects, key=lambda x:x.y(), reverse=True))
for object in objects:
if (object.isVisible()):
if (object.rotation() != 0.0):
origin = renderer.pixelToScreenCoords_(object.position())
painter.save()
painter.translate(origin)
painter.rotate(object.rotation())
painter.translate(-origin)
color = MapObjectItem.objectColor(object)
renderer.drawMapObject(painter, object, color)
if (object.rotation() != 0.0):
painter.restore()
elif (tp==ImageLayer and drawImages):
renderer.drawImageLayer(painter, imageLayer)
painter.translate(-layer.offset())
if (drawTileGrid):
prefs = preferences.Preferences.instance()
renderer.drawGrid(painter, QRectF(QPointF(), renderer.mapSize()),
prefs.gridColor())
painter.end()
renderer.setFlags(renderFlags)
示例11: render
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import fromScale [as 别名]
def render(self, mapFileName, imageFileName):
map = None
renderer = None
reader = MapReader()
map = reader.readMap(mapFileName)
if (not map):
qWarning("Error while reading " + mapFileName + ":\n" + reader.errorString())
return 1
x = map.orientation()
if x==Map.Orientation.Isometric:
renderer = IsometricRenderer(map)
elif x==Map.Orientation.Staggered:
renderer = StaggeredRenderer(map)
elif x==Map.Orientation.Hexagonal:
renderer = HexagonalRenderer(map)
else:
renderer = OrthogonalRenderer(map)
if (self.mTileSize > 0):
xScale = self.mTileSize / map.tileWidth()
yScale = self.mTileSize / map.tileHeight()
else:
xScale = yScale = self.mScale
mapSize = renderer.mapSize()
margins = map.computeLayerOffsetMargins()
mapSize.setWidth(mapSize.width() + margins.left() + margins.right())
mapSize.setHeight(mapSize.height() + margins.top() + margins.bottom())
mapSize.setWidth(mapSize.width()*xScale)
mapSize.setHeight(mapSize.height()*yScale)
image = QImage(mapSize, QImage.Format_ARGB32)
image.fill(Qt.transparent)
painter = QPainter(image)
if (xScale != 1.0 or yScale != 1.0):
if (self.mUseAntiAliasing):
painter.setRenderHints(QPainter.SmoothPixmapTransform |
QPainter.Antialiasing)
painter.setTransform(QTransform.fromScale(xScale, yScale))
painter.translate(margins.left(), margins.top())
# Perform a similar rendering than found in exportasimagedialog.py
for layer in map.layers():
if (not self.shouldDrawLayer(layer)):
continue
painter.setOpacity(layer.opacity())
painter.translate(layer.offset())
tileLayer = layer
imageLayer = layer
tp = type(layer)
if tp == TileLayer:
renderer.drawTileLayer(painter, tileLayer)
elif tp == ImageLayer:
renderer.drawImageLayer(painter, imageLayer)
painter.translate(-layer.offset())
painter.end()
# Save image
imageWriter = QImageWriter(imageFileName)
if (not imageWriter.write(image)):
qWarning("Error while writing " + imageFileName + ": " + imageWriter.errorString())
return 1
return 0