本文整理汇总了Python中pyqtcore.QVector.last方法的典型用法代码示例。如果您正苦于以下问题:Python QVector.last方法的具体用法?Python QVector.last怎么用?Python QVector.last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyqtcore.QVector
的用法示例。
在下文中一共展示了QVector.last方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Zoomable
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import last [as 别名]
class Zoomable(QObject):
scaleChanged = pyqtSignal(float)
def __init__(self, parent = None):
super().__init__(parent)
self.mScale = 1
self.mZoomFactors = QVector()
self.mGestureStartScale = 0
self.mComboBox = None
self.mComboRegExp = QRegExp("^\\s*(\\d+)\\s*%?\\s*$")
self.mComboValidator = None
for i in range(zoomFactorCount):
self.mZoomFactors.append(zoomFactors[i])
def setScale(self, scale):
if (scale == self.mScale):
return
self.mScale = scale
self.syncComboBox()
self.scaleChanged.emit(self.mScale)
def scale(self):
return self.mScale
def canZoomIn(self):
return self.mScale < self.mZoomFactors.last()
def canZoomOut(self):
return self.mScale > self.mZoomFactors.first()
##
# Changes the current scale based on the given mouse wheel \a delta.
#
# For convenience, the delta is assumed to be in the same units as
# QWheelEvent.delta, which is the distance that the wheel is rotated,
# in eighths of a degree.
##
def handleWheelDelta(self, delta):
if (delta <= -120):
self.zoomOut()
elif (delta >= 120):
self.zoomIn()
else:
# We're dealing with a finer-resolution mouse. Allow it to have finer
# control over the zoom level.
factor = 1 + 0.3 * qAbs(delta / 8 / 15)
if (delta < 0):
factor = 1 / factor
scale = qBound(self.mZoomFactors.first(),
self.mScale * factor,
self.mZoomFactors.back())
# Round to at most four digits after the decimal point
self.setScale(math.floor(scale * 10000 + 0.5) / 10000)
##
# Changes the current scale based on the given pinch gesture.
##
def handlePinchGesture(self, pinch):
if (not (pinch.changeFlags() & QPinchGesture.ScaleFactorChanged)):
return
x = pinch.state()
if x==Qt.NoGesture:
pass
elif x==Qt.GestureStarted:
self.mGestureStartScale = self.mScale
# fall through
elif x==Qt.GestureUpdated:
factor = pinch.scaleFactor()
scale = qBound(self.mZoomFactors.first(),
self.mGestureStartScale * factor,
self.mZoomFactors.back())
self.setScale(math.floor(scale * 10000 + 0.5) / 10000)
elif x==Qt.GestureFinished:
pass
elif x==Qt.GestureCanceled:
pass
##
# Returns whether images should be smoothly transformed when drawn at the
# current scale. This is the case when the scale is not 1 and smaller than
# 2.
##
def smoothTransform(self):
return self.mScale != 1.0 and self.mScale < 2.0
def setZoomFactors(self, factors):
self.mZoomFactors = factors
def connectToComboBox(self, comboBox):
if (self.mComboBox):
self.mComboBox.disconnect()
if (self.mComboBox.lineEdit()):
self.mComboBox.lineEdit().disconnect()
self.mComboBox.setValidator(None)
self.mComboBox = comboBox
if type(comboBox) is QComboBox:
self.mComboBox.clear()
for scale in self.mZoomFactors:
#.........这里部分代码省略.........