本文整理汇总了Python中PyQt4.QtGui.QTransform.inverted方法的典型用法代码示例。如果您正苦于以下问题:Python QTransform.inverted方法的具体用法?Python QTransform.inverted怎么用?Python QTransform.inverted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QTransform
的用法示例。
在下文中一共展示了QTransform.inverted方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scene_bbox
# 需要导入模块: from PyQt4.QtGui import QTransform [as 别名]
# 或者: from PyQt4.QtGui.QTransform import inverted [as 别名]
def scene_bbox(item, view=None):
"""
Returns the bounding box of an item in scene space.
If view is given and the object has the
QGraphicsItem::ItemIgnoresTransformations flag set, additional steps are
taken to compute the exact bounding box of the item.
"""
bbox = item.boundingRect()
if not (item.flags() & QGraphicsItem.ItemIgnoresTransformations):
# Normal item, simply map its bounding box to scene space
bbox = item.mapRectToScene(bbox)
else:
# Item with the ItemIgnoresTransformations flag, need to compute its
# bounding box with deviceTransform()
if view is not None:
vp_trans = view.viewportTransform()
else:
vp_trans = QTransform()
item_to_vp_trans = item.deviceTransform(vp_trans)
# Map bbox to viewport space
bbox = item_to_vp_trans.mapRect(bbox)
# Map bbox back to scene space
bbox = vp_trans.inverted()[0].mapRect(bbox)
return bbox
示例2: setImageMove
# 需要导入模块: from PyQt4.QtGui import QTransform [as 别名]
# 或者: from PyQt4.QtGui.QTransform import inverted [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
示例3: paintEvent
# 需要导入模块: from PyQt4.QtGui import QTransform [as 别名]
# 或者: from PyQt4.QtGui.QTransform import inverted [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()
示例4: paintEvent
# 需要导入模块: from PyQt4.QtGui import QTransform [as 别名]
# 或者: from PyQt4.QtGui.QTransform import inverted [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()