本文整理汇总了Python中AnyQt.QtGui.QFontMetrics.width方法的典型用法代码示例。如果您正苦于以下问题:Python QFontMetrics.width方法的具体用法?Python QFontMetrics.width怎么用?Python QFontMetrics.width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtGui.QFontMetrics
的用法示例。
在下文中一共展示了QFontMetrics.width方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paint
# 需要导入模块: from AnyQt.QtGui import QFontMetrics [as 别名]
# 或者: from AnyQt.QtGui.QFontMetrics import width [as 别名]
def paint(self, painter, option, widget=None):
rect = self.rect()
if self.isSelected():
option.state ^= QStyle.State_Selected
font = self.document().defaultFont()
painter.setFont(font)
if self.parent:
draw_text = self.node_inst.description
if self.parent.x() > self.x(): # node is to the left
fm = QFontMetrics(font)
x = rect.width() / 2 - fm.width(draw_text) - 4
else:
x = rect.width() / 2 + 4
painter.drawText(QPointF(x, -self.line_descent - 1), draw_text)
painter.save()
painter.setBrush(self.backgroundBrush)
painter.setPen(QPen(Qt.black, 3 if self.isSelected() else 0))
adjrect = rect.adjusted(-3, 0, 0, 0)
if not self.node_inst.children:
painter.drawRoundedRect(adjrect, 4, 4)
else:
painter.drawRect(adjrect)
painter.restore()
painter.setClipRect(rect)
return QGraphicsTextItem.paint(self, painter, option, widget)
示例2: __naturalsh
# 需要导入模块: from AnyQt.QtGui import QFontMetrics [as 别名]
# 或者: from AnyQt.QtGui.QFontMetrics import width [as 别名]
def __naturalsh(self):
fm = QFontMetrics(self.font())
spacing = self.__spacing
N = len(self.__items)
width = max((fm.width(text) for text in self.__items),
default=0)
height = N * fm.height() + (N - 1) * spacing
return QSizeF(width, height)
示例3: update_contents
# 需要导入模块: from AnyQt.QtGui import QFontMetrics [as 别名]
# 或者: from AnyQt.QtGui.QFontMetrics import width [as 别名]
def update_contents(self):
self.prepareGeometryChange()
self.setTextWidth(-1)
self.setTextWidth(self.document().idealWidth())
self.droplet.setPos(self.rect().center().x(), self.rect().height())
self.droplet.setVisible(bool(self.branches))
fm = QFontMetrics(self.document().defaultFont())
attr = self.node_inst.attr
self.attr_text_w = fm.width(attr.name if attr else "")
self.attr_text_h = fm.lineSpacing()
self.line_descent = fm.descent()
if self.pie is not None:
self.pie.setPos(self.rect().right(), self.rect().center().y())
示例4: _update_points_labels
# 需要导入模块: from AnyQt.QtGui import QFontMetrics [as 别名]
# 或者: from AnyQt.QtGui.QFontMetrics import width [as 别名]
def _update_points_labels(self):
if self.plotdata.points is None:
return
for point_label in self.plotdata.point_labels:
self.graph.plot_widget.removeItem(point_label)
self.plotdata.point_labels = []
sx, sy = self.graph.view_box.viewPixelSize()
for row in self.plotdata.points:
ti = TextItem()
metrics = QFontMetrics(ti.textItem.font())
text_width = ((RANGE.width())/2. - np.abs(row[0])) / sx
name = row[2].name
ti.setText(name)
ti.setTextWidth(text_width)
ti.setColor(QColor(0, 0, 0))
br = ti.boundingRect()
width = metrics.width(name) if metrics.width(name) < br.width() else br.width()
width = sx * (width + 5)
height = sy * br.height()
ti.setPos(row[0] - (row[0] < 0) * width, row[1] + (row[1] > 0) * height)
self.plotdata.point_labels.append(ti)
self.graph.plot_widget.addItem(ti)
示例5: __init__
# 需要导入模块: from AnyQt.QtGui import QFontMetrics [as 别名]
# 或者: from AnyQt.QtGui.QFontMetrics import width [as 别名]
def __init__(self, model, node_inst, parent=None):
super().__init__(parent)
self.model = model
self.node_inst = node_inst
fm = QFontMetrics(self.document().defaultFont())
attr = node_inst.attr
self.attr_text_w = fm.width(attr.name if attr else "")
self.attr_text_h = fm.lineSpacing()
self.line_descent = fm.descent()
self._rect = None
if model.domain.class_var.is_discrete:
self.pie = PieChart(node_inst.value, 8, self)
else:
self.pie = None
示例6: __init__
# 需要导入模块: from AnyQt.QtGui import QFontMetrics [as 别名]
# 或者: from AnyQt.QtGui.QFontMetrics import width [as 别名]
def __init__(self, tree_adapter, node_inst, parent=None):
super().__init__(parent)
self.tree_adapter = tree_adapter
self.model = self.tree_adapter.model
self.node_inst = node_inst
fm = QFontMetrics(self.document().defaultFont())
attr = self.tree_adapter.attribute(node_inst)
self.attr_text_w = fm.width(attr.name if attr else "")
self.attr_text_h = fm.lineSpacing()
self.line_descent = fm.descent()
self._rect = None
if self.model.domain.class_var.is_discrete:
self.pie = PieChart(self.tree_adapter.get_distribution(node_inst)[0], 8, self)
else:
self.pie = None