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


Python QtGui.QFontMetricsF类代码示例

本文整理汇总了Python中PyQt4.QtGui.QFontMetricsF的典型用法代码示例。如果您正苦于以下问题:Python QFontMetricsF类的具体用法?Python QFontMetricsF怎么用?Python QFontMetricsF使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: drawMarkings

    def drawMarkings(self, painter):
        painter.save()
        painter.translate(self.width() / 2, self.height() / 2)
        scale = min((self.width() - self._margins) / 120.0,
                    (self.height() - self._margins) / 120.0)
        painter.scale(scale, scale)

        font = QFont(self.font())
        font.setPixelSize(10)
        metrics = QFontMetricsF(font)

        painter.setFont(font)
        painter.setPen(self.palette().color(QPalette.Shadow))

        i = 0
        while i < 360:
            if i % 45 == 0:
                painter.drawLine(0, -40, 0, -50)
                painter.drawText(-metrics.width(self._pointText[i]) / 2.0, -52,
                                 self._pointText[i])
            else:
                painter.drawLine(0, -45, 0, -50)
            painter.rotate(15)
            i += 15
        painter.restore()
开发者ID:jrenken,项目名称:qgis-PosiView,代码行数:25,代码来源:compass.py

示例2: __init__

	def __init__(self, leftFlow = 0, rightFlow = 0, maxFlow = 100, parent = None):
		super(YPipeWidget, self).__init__(parent)

		self.leftSpinBox = QSpinBox(self)
		self.leftSpinBox.setRange(0, maxFlow)
		self.leftSpinBox.setValue(leftFlow)
		self.leftSpinBox.setSuffix(" l/s")
		self.leftSpinBox.setAlignment(Qt.AlignRight|Qt.AlignVCenter)
		self.connect(self.leftSpinBox, SIGNAL("valueChanged(int)"), self.valueChanged)

		self.rightSpinBox = QSpinBox(self)
		self.rightSpinBox.setRange(0, maxFlow)
		self.rightSpinBox.setValue(rightFlow)
		self.rightSpinBox.setSuffix(" l/s")
		self.rightSpinBox.setAlignment(Qt.AlignRight|Qt.AlignVCenter)
		self.connect(self.rightSpinBox, SIGNAL("valueChanged(int)"), self.valueChanged)

		self.label = QLabel(self)
		self.label.setFrameStyle(QFrame.StyledPanel | QFrame.Sunken)
		self.label.setAlignment(Qt.AlignCenter)
		fm = QFontMetricsF(self.font())
		self.label.setMinimumWidth(fm.width(" 999 l/s "))

		self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))

		self.setMinimumSize(self.minimumSizeHint())
		self.valueChanged()
开发者ID:vamtiger-project,项目名称:python-desktop-gui-practice,代码行数:27,代码来源:23-ypipewidget_practice.py

示例3: plot

    def plot(self, under, over):
    
        if not under:
            return
        
        ctx = PaintGL.instance().currentContext
        painter = ctx.painter
        plotm = PlotModule.instance()
        plot_width, plot_height = plotm.getPlotWindow()
        
        metrics = QFontMetricsF(QFont())

        painter.save()
        painter.setPen(QColor(0, 0, 160))
        painter.setBrush(QColor(255, 255, 255, 192))
        painter.setCompositionMode(painter.CompositionMode_SourceOver)

        for point, label in self.locations:
            ok, x, y = plotm.GeoToPhys(point.x(), point.y())
            y = plot_height - y
            if ok:
                rect = QRectF(x, y, metrics.width(label) + 8, metrics.height() + 8)
                painter.drawRect(rect)
                painter.drawText(rect, Qt.AlignCenter, label)

        painter.restore()
开发者ID:metno,项目名称:python-diana,代码行数:26,代码来源:manager.py

示例4: minimumSizeHint

 def minimumSizeHint(self):
     font = QFont(self.font())
     font.setPointSize(font.pointSize() - 1)
     fm = QFontMetricsF(font)
     return QSize(fm.width(FractionSlider.WSTRING) *
                  self.__denominator,
                  (fm.height() * 4) + FractionSlider.YMARGIN)
开发者ID:imagingearth,项目名称:PyQt4-Examples,代码行数:7,代码来源:fractionslider.py

示例5: minimumSizeHint

	def minimumSizeHint(self):
		"Pour être sûr que le texte du chrono ne soit pas tronqué"
		font = QFont(self.font())
		font.setPointSize(font.pointSize() - 1)
		fm = QFontMetricsF(font)
		l = fm.width(TracerChrono.TAILLE*2) # + 10.
		L = fm.height() + 2.
		return QSize(l, L)
开发者ID:Ptaah,项目名称:Ekd,代码行数:8,代码来源:mplayer.py

示例6: _find_font

 def _find_font(self):
     font = QFont()
     wanted_size = self._point_size
     font.setStyleStrategy(QFont.StyleStrategy(QFont.OpenGLCompatible | QFont.PreferAntialias))
     fm = QFontMetricsF(font)
     width = fm.width("888")
     ratio = 1.8*wanted_size/max(width, fm.ascent())
     self._font = font
     self._font_zoom = ratio
开发者ID:PierreBdR,项目名称:point_tracker,代码行数:9,代码来源:parameters.py

示例7: resizeEvent

 def resizeEvent(self, event=None):
     fm = QFontMetricsF(self.font())
     x = (self.width() - self.label.width()) / 2
     y = self.height() - (fm.height() * 1.5)
     self.label.move(x, y)
     y = self.height() / 60.0
     x = (self.width() / 4.0) - self.leftSpinBox.width()
     self.leftSpinBox.move(x, y)
     x = self.width() - (self.width() / 4.0)
     self.rightSpinBox.move(x, y)
开发者ID:dpeinado,项目名称:restec,代码行数:10,代码来源:ypipewidget.py

示例8: paintEvent

 def paintEvent(self, event=None):
     font = QFont(self.font())
     font.setPointSize(font.pointSize() - 1)
     fm = QFontMetricsF(font)
     fracWidth = fm.width(FractionSlider.WSTRING)
     indent = fm.boundingRect("9").width() / 2.0
     if not X11:
         fracWidth *= 1.5
     span = self.width() - (FractionSlider.XMARGIN * 2)
     value = self.__numerator / float(self.__denominator)
     painter = QPainter(self)
     painter.setRenderHint(QPainter.Antialiasing)
     painter.setRenderHint(QPainter.TextAntialiasing)
     painter.setPen(self.palette().color(QPalette.Mid))
     painter.setBrush(self.palette().brush(
             QPalette.AlternateBase))
     painter.drawRect(self.rect())
     segColor = QColor(Qt.green).dark(120)
     segLineColor = segColor.dark()
     painter.setPen(segLineColor)
     painter.setBrush(segColor)
     painter.drawRect(FractionSlider.XMARGIN,
                      FractionSlider.YMARGIN, span, fm.height())
     textColor = self.palette().color(QPalette.Text)
     segWidth = span / self.__denominator
     segHeight = fm.height() * 2
     nRect = fm.boundingRect(FractionSlider.WSTRING)
     x = FractionSlider.XMARGIN
     yOffset = segHeight + fm.height()
     for i in range(self.__denominator + 1):
         painter.setPen(segLineColor)
         painter.drawLine(x, FractionSlider.YMARGIN, x, segHeight)
         painter.setPen(textColor)
         y = segHeight
         rect = QRectF(nRect)
         rect.moveCenter(QPointF(x, y + fm.height() / 2.0))
         painter.drawText(rect, Qt.AlignCenter,
                          QString.number(i))
         y = yOffset
         rect.moveCenter(QPointF(x, y + fm.height() / 2.0))
         painter.drawText(rect, Qt.AlignCenter,
                          QString.number(self.__denominator))
         painter.drawLine(QPointF(rect.left() + indent, y),
                          QPointF(rect.right() - indent, y))
         x += segWidth
     span = int(span)
     y = FractionSlider.YMARGIN - 0.5
     triangle = [QPointF(value * span, y),
                 QPointF((value * span) +
                         (2 * FractionSlider.XMARGIN), y),
                 QPointF((value * span) +
                         FractionSlider.XMARGIN, fm.height())]
     painter.setPen(Qt.yellow)
     painter.setBrush(Qt.darkYellow)
     painter.drawPolygon(QPolygonF(triangle))
开发者ID:imagingearth,项目名称:PyQt4-Examples,代码行数:55,代码来源:fractionslider.py

示例9: selectValues

 def selectValues(self, length, is_vertical, painter = None):
     if painter is not None:
         metric = QFontMetricsF(self.font, painter.device())
     else:
         metric = QFontMetricsF(self.font)
     min_dist = 1
     if not is_vertical: # Find the maximum size of 2 figures
         test = [ str(i)*2 for i in range(10) ]
         for t in test:
             min_dist = max(min_dist, metric.boundingRect(t).width())
     return self._selectValues_direct(length, is_vertical, metric, min_dist)
开发者ID:PierreBdR,项目名称:point_tracker,代码行数:11,代码来源:scale_bar.py

示例10: _update_margin_line

 def _update_margin_line(self, font):
     # Fix for older version of Qt which doens't has ForceIntegerMetrics
     if "ForceIntegerMetrics" in dir(QFont):
         self.document().defaultFont().setStyleStrategy(
             QFont.ForceIntegerMetrics)
     font_metrics = QFontMetricsF(self.document().defaultFont())
     if (font_metrics.width("#") * settings.MARGIN_LINE) == \
        (font_metrics.width(" ") * settings.MARGIN_LINE):
         self.pos_margin = font_metrics.width('#') * settings.MARGIN_LINE
     else:
         char_width = font_metrics.averageCharWidth()
         self.pos_margin = char_width * settings.MARGIN_LINE
开发者ID:akatrevorjay,项目名称:ninja-ide,代码行数:12,代码来源:editor.py

示例11: getLinkPointForParameter

 def getLinkPointForParameter(self, paramIndex):
     offsetX = 25
     if isinstance(self.element, Algorithm) and self.element.paramsFolded:
         paramIndex = -1
         offsetX = 17
     font = QFont('Verdana', 8)
     fm = QFontMetricsF(font)
     if isinstance(self.element, Algorithm):
         h = -(fm.height() * 1.2) * (paramIndex + 2) - fm.height() / 2.0 + 8
         h = h - ModelerGraphicItem.BOX_HEIGHT / 2.0
     else:
         h = 0
     return QPointF(-ModelerGraphicItem.BOX_WIDTH / 2 + offsetX, h)
开发者ID:ar-jan,项目名称:QGIS,代码行数:13,代码来源:ModelerGraphicItem.py

示例12: getAdjustedText

    def getAdjustedText(self, text):
        font = QFont('Verdana', 8)
        fm = QFontMetricsF(font)
        w = fm.width(text)
        if w < self.BOX_WIDTH - 25 - FlatButtonGraphicItem.WIDTH:
            return text

        text = text[0:-3] + '...'
        w = fm.width(text)
        while w > self.BOX_WIDTH - 25 - FlatButtonGraphicItem.WIDTH:
            text = text[0:-4] + '...'
            w = fm.width(text)
        return text
开发者ID:ar-jan,项目名称:QGIS,代码行数:13,代码来源:ModelerGraphicItem.py

示例13: getLinkPointForOutput

 def getLinkPointForOutput(self, outputIndex):
     if isinstance(self.element, Algorithm):
         outputIndex = outputIndex if not self.element.outputsFolded else -1
         text = self.getAdjustedText(self.element.algorithm.outputs[outputIndex].description)
         font = QFont("Verdana", 8)
         fm = QFontMetricsF(font)
         w = fm.width(text)
         h = fm.height() * 1.2 * (outputIndex + 1) + fm.height() / 2.0
         y = h + ModelerGraphicItem.BOX_HEIGHT / 2.0 + 5
         x = -ModelerGraphicItem.BOX_WIDTH / 2 + 33 + w + 5 if not self.element.outputsFolded else 10
         return QPointF(x, y)
     else:
         return QPointF(0, 0)
开发者ID:olivierdalang,项目名称:QGIS,代码行数:13,代码来源:ModelerGraphicItem.py

示例14: set_font

 def set_font(self, family=settings.FONT_FAMILY, size=settings.FONT_SIZE):
     font = QFont(family, size)
     self.document().setDefaultFont(font)
     # Fix for older version of Qt which doens't has ForceIntegerMetrics
     if "ForceIntegerMetrics" in dir(QFont):
         self.document().defaultFont().setStyleStrategy(
             QFont.ForceIntegerMetrics)
     font_metrics = QFontMetricsF(self.document().defaultFont())
     if (font_metrics.width("#") * settings.MARGIN_LINE) == \
        (font_metrics.width(" ") * settings.MARGIN_LINE):
         self.pos_margin = font_metrics.width('#') * settings.MARGIN_LINE
     else:
         char_width = font_metrics.averageCharWidth()
         self.pos_margin = char_width * settings.MARGIN_LINE
开发者ID:alekibango,项目名称:ninja-ide,代码行数:14,代码来源:editor.py

示例15: boundingRect

    def boundingRect(self):
        font = QFont('Verdana', 8)
        fm = QFontMetricsF(font)
        unfolded = isinstance(self.element, Algorithm) and not self.element.paramsFolded
        numParams = len(self.element.algorithm.parameters) if unfolded else 0
        unfolded = isinstance(self.element, Algorithm) and not self.element.outputsFolded
        numOutputs = len(self.element.algorithm.outputs) if unfolded else 0

        hUp = fm.height() * 1.2 * (numParams + 2)
        hDown = fm.height() * 1.2 * (numOutputs + 2)
        rect = QRectF(-(ModelerGraphicItem.BOX_WIDTH + 2) / 2,
                      -(ModelerGraphicItem.BOX_HEIGHT + 2) / 2 - hUp,
                      ModelerGraphicItem.BOX_WIDTH + 2,
                      ModelerGraphicItem.BOX_HEIGHT + hDown + hUp)
        return rect
开发者ID:ar-jan,项目名称:QGIS,代码行数:15,代码来源:ModelerGraphicItem.py


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