本文整理汇总了Python中PyQt5.Qt.QFontMetrics.leading方法的典型用法代码示例。如果您正苦于以下问题:Python QFontMetrics.leading方法的具体用法?Python QFontMetrics.leading怎么用?Python QFontMetrics.leading使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QFontMetrics
的用法示例。
在下文中一共展示了QFontMetrics.leading方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyQt5.Qt import QFontMetrics [as 别名]
# 或者: from PyQt5.Qt.QFontMetrics import leading [as 别名]
def __init__(self, text='', width=0, font=None, img=None, max_height=100, align=Qt.AlignCenter):
self.layouts = []
self._position = Point(0, 0)
self.leading = self.line_spacing = 0
if font is not None:
fm = QFontMetrics(font, img)
self.leading = fm.leading()
self.line_spacing = fm.lineSpacing()
for text in text.split('<br>') if text else ():
text, formats = parse_text_formatting(sanitize(text))
l = QTextLayout(unescape_formatting(text), font, img)
l.setAdditionalFormats(formats)
to = QTextOption(align)
to.setWrapMode(QTextOption.WrapAtWordBoundaryOrAnywhere)
l.setTextOption(to)
l.beginLayout()
height = 0
while height + 3*self.leading < max_height:
line = l.createLine()
if not line.isValid():
break
line.setLineWidth(width)
height += self.leading
line.setPosition(QPointF(0, height))
height += line.height()
max_height -= height
l.endLayout()
if self.layouts:
self.layouts.append(self.leading)
else:
self._position = Point(l.position().x(), l.position().y())
self.layouts.append(l)
if self.layouts:
self.layouts.append(self.leading)