本文整理汇总了Python中AnyQt.QtWidgets.QGraphicsTextItem.paint方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsTextItem.paint方法的具体用法?Python QGraphicsTextItem.paint怎么用?Python QGraphicsTextItem.paint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QGraphicsTextItem
的用法示例。
在下文中一共展示了QGraphicsTextItem.paint方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paint
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsTextItem import paint [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: paint
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsTextItem import paint [as 别名]
def paint(self, painter, option, widget=None):
QGraphicsTextItem.paint(self, painter, option, widget)
# Draw placeholder text if necessary
if not (self.toPlainText() and self.toHtml()) and \
self.__placeholderText and \
not (self.hasFocus() and \
self.textInteractionFlags() & Qt.TextEditable):
brect = self.boundingRect()
painter.setFont(self.font())
metrics = painter.fontMetrics()
text = metrics.elidedText(self.__placeholderText, Qt.ElideRight,
brect.width())
color = self.defaultTextColor()
color.setAlpha(min(color.alpha(), 150))
painter.setPen(QPen(color))
painter.drawText(brect, Qt.AlignTop | Qt.AlignLeft, text)
示例3: paint
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsTextItem import paint [as 别名]
def paint(self, painter, option, widget=0):
painter.save()
painter.setBrush(self.backgroundBrush)
painter.setPen(QPen(Qt.gray))
rect = self.rect()
painter.drawRoundedRect(rect, 4, 4)
painter.restore()
painter.setClipRect(rect)
return QGraphicsTextItem.paint(self, painter, option, widget)