本文整理汇总了Python中PyQt4.QtGui.QTransform.translate方法的典型用法代码示例。如果您正苦于以下问题:Python QTransform.translate方法的具体用法?Python QTransform.translate怎么用?Python QTransform.translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QTransform
的用法示例。
在下文中一共展示了QTransform.translate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paintEvent
# 需要导入模块: from PyQt4.QtGui import QTransform [as 别名]
# 或者: from PyQt4.QtGui.QTransform import translate [as 别名]
def paintEvent(self, event ):
"""QToolBar.paintEvent reimplementation
Draws buttons, dock icon and text
"""
rect = self._spacer.rect()
painter = QPainter( self )
transform = QTransform()
transform.translate(self._spacer.pos().x(), self._spacer.pos().y())
painter.setTransform( transform )
""" Not supported currently
if self._dock.features() & QDockWidget.DockWidgetVerticalTitleBar :
transform = QTransform()
rect.setSize( QSize( rect.height(), rect.width() ) )
transform.rotate( -90 )
transform.translate( -rect.width(), 0 )
painter.setTransform( transform )
"""
# icon / title
optionB = QStyleOptionButton()
optionB.initFrom( self._dock )
optionB.rect = rect
optionB.text = self._dock.windowTitle()
optionB.iconSize = self.iconSize()
optionB.icon = self._dock.windowIcon()
self.style().drawControl( QStyle.CE_PushButtonLabel, optionB, painter, self._dock )
示例2: __updateText
# 需要导入模块: from PyQt4.QtGui import QTransform [as 别名]
# 或者: from PyQt4.QtGui.QTransform import translate [as 别名]
def __updateText(self):
self.prepareGeometryChange()
if self.__sourceName or self.__sinkName:
if self.__sourceName != self.__sinkName:
text = u"{0} \u2192 {1}".format(self.__sourceName,
self.__sinkName)
else:
# If the names are the same show only one.
# Is this right? If the sink has two input channels of the
# same type having the name on the link help elucidate
# the scheme.
text = self.__sourceName
else:
text = ""
self.linkTextItem.setPlainText(text)
path = self.curveItem.path()
if not path.isEmpty():
center = path.pointAtPercent(0.5)
angle = path.angleAtPercent(0.5)
brect = self.linkTextItem.boundingRect()
transform = QTransform()
transform.translate(center.x(), center.y())
transform.rotate(-angle)
# Center and move above the curve path.
transform.translate(-brect.width() / 2, -brect.height())
self.linkTextItem.setTransform(transform)
示例3: updateTransfrom
# 需要导入模块: from PyQt4.QtGui import QTransform [as 别名]
# 或者: from PyQt4.QtGui.QTransform import translate [as 别名]
def updateTransfrom( self ):
if self.updating : return
self.updating = True
trans = QTransform()
trans.translate( self.valueToX( -self.scrollX ) + self.offsetX, self.valueToY( -self.scrollY ) )
self.setTransform( trans )
self.update()
self.updating = False
示例4: transform
# 需要导入模块: from PyQt4.QtGui import QTransform [as 别名]
# 或者: from PyQt4.QtGui.QTransform import translate [as 别名]
def transform(self):
try:
return self.__dict__['transform'] if self.scale else QTransform()
except KeyError:
transform = QTransform()
image = self.client.image
if image is not None and not image.isNull():
scale = min(self.width()/image.width(), self.height()/image.height())
transform.translate((self.width() - image.width()*scale)/2, (self.height() - image.height()*scale)/2)
transform.scale(scale, scale)
transform = self.__dict__.setdefault('transform', transform)
return transform
示例5: setImageMove
# 需要导入模块: from PyQt4.QtGui import QTransform [as 别名]
# 或者: from PyQt4.QtGui.QTransform import translate [as 别名]
def setImageMove(self, scale, pos, angle):
log_debug("New scale = %s" % (scale,))
self.scale = scale
self.min_scale = self.data_manager.minScale()
self.img_scale = (scale[0]/self.min_scale, scale[1]/self.min_scale)
back_matrix = QTransform()
back_matrix.scale(*self.img_scale)
back_matrix.translate(pos.x(), pos.y())
back_matrix.rotate(angle)
self.back_matrix = back_matrix
rect = back_matrix.mapRect(QRectF(self.background_image.rect()))
inv, ok = back_matrix.inverted()
if not ok:
raise ValueError("The movement is not invertible !?!")
self.invert_back_matrix = inv
self.real_scene_rect = rect
示例6: paintEvent
# 需要导入模块: from PyQt4.QtGui import QTransform [as 别名]
# 或者: from PyQt4.QtGui.QTransform import translate [as 别名]
def paintEvent(self, event):
painter = QPainter(self)
painter.fillRect(self.rect(), QColor('#101010'))
image = self._image
if image is not None:
if self.height() < 240:
fast_scaler = QTransform()
scale = 297/image.height()
if self.mirror:
fast_scaler.scale(-scale, scale)
else:
fast_scaler.scale(scale, scale)
rect = event.rect()
painter.drawPixmap(rect, QPixmap.fromImage(image.transformed(fast_scaler)).scaledToHeight(self.height(), Qt.SmoothTransformation), rect)
else:
transform = QTransform()
scale = min(self.width()/image.width(), self.height()/image.height())
if self.mirror:
transform.translate((self.width() + image.width()*scale)/2, (self.height() - image.height()*scale)/2)
transform.scale(-scale, scale)
else:
transform.translate((self.width() - image.width()*scale)/2, (self.height() - image.height()*scale)/2)
transform.scale(scale, scale)
inverse_transform, invertible = transform.inverted()
rect = inverse_transform.mapRect(event.rect()).adjusted(-1, -1, 1, 1).intersected(image.rect())
painter.setTransform(transform)
if self.height() > 400:
painter.drawPixmap(rect, QPixmap.fromImage(image), rect)
else:
painter.drawImage(rect, image, rect)
painter.end()
示例7: QTerminalWidget
# 需要导入模块: from PyQt4.QtGui import QTransform [as 别名]
# 或者: from PyQt4.QtGui.QTransform import translate [as 别名]
#.........这里部分代码省略.........
elif s == "~b": # F2 -> Run ESC M
self._kbdfunc(77, True)
elif s == "~c": # F3 -> Cmds ESC N
self._kbdfunc(78, True)
elif s == "~d": # F4 -> SST ESC P
self._kbdfunc(80, True)
elif s == "~e": # F5 -> -Line ESC I
self._kbdfunc(73, True)
elif s == "~f": # F6 -> LC ESC O
self._kbdfunc(79, True)
# elif s == "~g": # F7 -> Ctrl ESC S
# self._kbdfunc(83, True)
else:
pass
if (event.isAutoRepeat() and not text) :
time.sleep(0.05)
event.accept()
#
# internal methods
#
def _update_metrics(self):
fm = self.fontMetrics()
self._char_height = fm.height()
self._char_width = fm.width("W")
#
# update cursor position
#
def _update_cursor_rect(self):
if self._cursortype== CURSOR_OFF or (self._cursor_col== -1 and self._cursor_row==-1):
return
cx, cy = self._pos2pixel(self._cursor_col, self._cursor_row)
self._transform.reset()
self._transform.translate(cx,cy)
self._cursor_update=True
self._blink=True
#
# determine pixel position from rowl, column
#
def _pos2pixel(self, col, row):
x = (col * self._char_width)
y = row * self._char_height
return x, y
#
# paint cursor
#
def _paint_cursor(self, painter):
if self._cursortype== CURSOR_OFF or (self._cursor_col== -1 and self._cursor_row==-1):
return
#
# cursor position was updated initialize some variables
#
if self._cursor_update:
self._cursor_update= False
self._blink_brush=QBrush(self._cursor_color)
self._blink_pen=QPen(self._cursor_color)
self._blink_pen.setStyle(0)
if self._cursor_attr:
self._noblink_background_color = self._color_scheme[1]
self._noblink_foreground_color = self._color_scheme[0]
else:
self._noblink_background_color = self._color_scheme[0]
self._noblink_foreground_color = self._color_scheme[1]
self._noblink_brush = QBrush(self._noblink_background_color)
#
# blink on: draw cursor
示例8: paintEvent
# 需要导入模块: from PyQt4.QtGui import QTransform [as 别名]
# 或者: from PyQt4.QtGui.QTransform import translate [as 别名]
def paintEvent(self, event):
painter = QPainter(self)
width = self.width()
height = self.height()
if DEBUG:
painter.fillRect(0, 0, width, height, Qt.blue)
else:
painter.fillRect(event.rect(), self.plot.canvas_color)
y_min_scale = self.plot.y_scale.value_min
y_max_scale = self.plot.y_scale.value_max
factor_x = float(width) / self.plot.history_length_x
factor_y = float(height - 1) / max(
y_max_scale - y_min_scale, EPSILON
) # -1 to accommodate the 1px width of the curve
if self.plot.x_min != None and self.plot.x_max != None:
x_min = self.plot.x_min
x_max = self.plot.x_max
if self.plot.curve_start == "left":
curve_x_offset = 0
else:
curve_x_offset = round((self.plot.history_length_x - (x_max - x_min)) * factor_x)
transform = QTransform()
transform.translate(
curve_x_offset, height - 1 + self.plot.curve_y_offset
) # -1 to accommodate the 1px width of the curve
transform.scale(factor_x, -factor_y)
transform.translate(-x_min, -y_min_scale)
if self.plot.curve_motion_granularity > 1:
self.plot.partial_update_width = math.ceil(transform.map(QLineF(0, 0, 1.5, 0)).length())
inverted_event_rect = transform.inverted()[0].mapRect(QRectF(event.rect()))
painter.save()
painter.setTransform(transform)
for c in range(len(self.plot.curves_x)):
if not self.plot.curves_visible[c]:
continue
curve_x = self.plot.curves_x[c]
curve_y = self.plot.curves_y[c]
path = QPainterPath()
lineTo = path.lineTo
if self.plot.curve_motion_granularity > 1:
start = max(min(bisect.bisect_left(curve_x, inverted_event_rect.left()), len(curve_x) - 1) - 1, 0)
else:
start = 0
path.moveTo(curve_x[start], curve_y[start])
for i in xrange(start + 1, len(curve_x)):
lineTo(curve_x[i], curve_y[i])
painter.setPen(self.plot.configs[c][1])
painter.drawPath(path)
painter.restore()