当前位置: 首页>>代码示例>>Python>>正文


Python QVector.count方法代码示例

本文整理汇总了Python中pyqtcore.QVector.count方法的典型用法代码示例。如果您正苦于以下问题:Python QVector.count方法的具体用法?Python QVector.count怎么用?Python QVector.count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyqtcore.QVector的用法示例。


在下文中一共展示了QVector.count方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Zoomable

# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import count [as 别名]

#.........这里部分代码省略.........
        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:
                self.mComboBox.addItem(scaleToString(scale), scale)
            self.syncComboBox()
            self.mComboBox.activated.connect(self.comboActivated)
            self.mComboBox.setEditable(True)
            self.mComboBox.setInsertPolicy(QComboBox.NoInsert)
            self.mComboBox.lineEdit().editingFinished.connect(self.comboEdited)
            if (not self.mComboValidator):
                self.mComboValidator = QRegExpValidator(self.mComboRegExp, self)
            self.mComboBox.setValidator(self.mComboValidator)

    def zoomIn(self):
        for scale in self.mZoomFactors:
            if (scale > self.mScale):
                self.setScale(scale)
                break

    def zoomOut(self):
        for i in range(self.mZoomFactors.count() - 1, -1, -1):
            if (self.mZoomFactors[i] < self.mScale):
                self.setScale(self.mZoomFactors[i])
                break

    def resetZoom(self):
        self.setScale(1)

    def comboActivated(self, index):
        self.setScale(self.mComboBox.itemData(index))

    def comboEdited(self):
        pos = self.mComboRegExp.indexIn(self.mComboBox.currentText())
        pos != -1
        scale = qBound(self.mZoomFactors.first(), Float(self.mComboRegExp.cap(1)) / 100.0, self.mZoomFactors.last())
        self.setScale(scale)

    def syncComboBox(self):
        if (not self.mComboBox):
            return
        index = self.mComboBox.findData(self.mScale)
        # For a custom scale, the current index must be set to -1
        self.mComboBox.setCurrentIndex(index)
        self.mComboBox.setEditText(scaleToString(self.mScale))
开发者ID:theall,项目名称:Python-Tiled,代码行数:104,代码来源:zoomable.py


注:本文中的pyqtcore.QVector.count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。