本文整理汇总了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()
示例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()
示例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()
示例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)
示例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)
示例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
示例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)
示例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))
示例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)
示例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
示例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)
示例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
示例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)
示例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
示例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