本文整理汇总了Python中PyQt5.QtWidgets.QGraphicsTextItem.document方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsTextItem.document方法的具体用法?Python QGraphicsTextItem.document怎么用?Python QGraphicsTextItem.document使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QGraphicsTextItem
的用法示例。
在下文中一共展示了QGraphicsTextItem.document方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createImage
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import document [as 别名]
def createImage(self, transform):
if self.type == DemoTextItem.DYNAMIC_TEXT:
return None
sx = min(transform.m11(), transform.m22())
sy = max(transform.m22(), sx)
textItem = QGraphicsTextItem()
textItem.setHtml(self.text)
textItem.setTextWidth(self.textWidth)
textItem.setFont(self.font)
textItem.setDefaultTextColor(self.textColor)
textItem.document().setDocumentMargin(2)
w = textItem.boundingRect().width()
h = textItem.boundingRect().height()
image = QImage(int(w * sx), int(h * sy),
QImage.Format_ARGB32_Premultiplied)
image.fill(QColor(0, 0, 0, 0).rgba())
painter = QPainter(image)
painter.scale(sx, sy)
style = QStyleOptionGraphicsItem()
textItem.paint(painter, style, None)
return image
示例2: set_functions_list
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import document [as 别名]
def set_functions_list(self, functionsList, prefix="", sufix=""):
self.funtionsList = functionsList
self.funtionsListItems = []
self.maxHeight = 0
tempHeight = 0
for element in functionsList:
tempElement = QGraphicsTextItem(self)
tempElement.setPlainText(prefix + element + sufix)
tempElement.setPos(0, tempHeight)
tempHeight += tempElement.document().size().height()
if self.maxWidth < tempElement.document().size().width():
self.maxWidth = tempElement.document().size().width()
self.funtionsListItems.append(tempElement)
self.maxHeight = tempHeight
示例3: ClassModel
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import document [as 别名]
class ClassModel(QGraphicsItem):
def __init__(self, parent=None, graphicView=None, graphicScene=None):
super(ClassModel, self).__init__()
self.set_default_data()
self.className = QGraphicsTextItem(self)
self.functionsItem = FunctionsContainerModel(self)
self.className.setPlainText(self.defaultClassName)
self.setFlag(self.ItemIsMovable)
self.setFlag(self.ItemSendsGeometryChanges)
self.functionsItem.setPos(0, self.__get_title_height())
self.attributesItem = FunctionsContainerModel(self)
self.attributesItem.setPos(0, self.functionsItem.get_height())
def set_default_data(self):
self.maxWidth = 100
self.defaultClassNameHeight = 30
self.defaultClassName = "No name"
def set_functions_list(self, functionsList):
self.functionsItem.set_functions_list(functionsList, "*", "()")
self.update_positions()
def set_attributes_list(self, attributesList):
self.attributesItem.set_functions_list(attributesList)
self.update_positions()
def set_class_name(self, className):
self.className.setPlainText(className)
def _get_width(self):
self.__calc_max_width()
return self.maxWidth
def __get_title_height(self):
titleHeight = self.defaultClassNameHeight
if titleHeight == self.className.document().size().height():
titleHeight = self.className.document().size().height()
return titleHeight
def get_height(self):
summary = self.defaultClassNameHeight
summary += self.functionsItem.get_height()
summary += self.attributesItem.get_height()
return summary
def __calc_max_width(self):
if self.maxWidth < self.className.document().size().width():
self.maxWidth = self.className.document().size().width()
if hasattr(self, "functionsItem"):
if self.maxWidth < self.functionsItem.get_width():
self.maxWidth = self.functionsItem.get_width()
if hasattr(self, "attributesItem"):
if self.maxWidth < self.attributesItem.get_width():
self.maxWidth = self.attributesItem.get_width()
def set_bg_color(self, qColor):
self.backgroundColor = qColor
def set_method_list(self, itemList):
self.methodList = itemList
def update_positions(self):
self.functionsItem.setPos(0, self.__get_title_height())
self.attributesItem.setPos(
0, self.functionsItem.y() + self.functionsItem.get_height())
def paint(self, painter, option, widget):
gradient = QRadialGradient(-3, -3, 10)
if option.state & QStyle.State_Sunken:
gradient.setCenter(3, 3)
gradient.setFocalPoint(3, 3)
gradient.setColorAt(0, QColor(Qt.yellow).light(120))
else:
gradient.setColorAt(0, QColor(Qt.yellow).light(120))
painter.setBrush(gradient)
painter.setPen(QPen(Qt.black, 0))
painter.drawRoundedRect(self.boundingRect(), 3, 3)
def boundingRect(self):
return QRectF(0, 0, self._get_width(), self.get_height())
def add_edge(self, edge):
self.myEdge = edge
edge.adjust()