本文整理汇总了Python中PyQt5.QtWidgets.QGraphicsTextItem类的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsTextItem类的具体用法?Python QGraphicsTextItem怎么用?Python QGraphicsTextItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QGraphicsTextItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, *args):
QGraphicsScene.__init__(self, *args)
# Add a graphic item, not responsive to gestures??
text = QGraphicsTextItem("Test")
text.setTextInteractionFlags(Qt.TextEditorInteraction)
self.addItem(text)
示例2: focusOutEvent
def focusOutEvent(self, event):
'''Handle focus out event.
Argument(s):
event (QFocusEvent ): Focus event
'''
QGraphicsTextItem.focusOutEvent(self, event)
# Create a fake node to test if label is valid with pydot
fakeNode = ("fake[" + NodeDotAttrs.label.value +
"=" + self.toPlainText() + "]")
pydotGraph = graph_from_dot_data("graph{" + fakeNode + "}")
# Label is valid: we can do the update
if pydotGraph:
dicDotAttrs = {
NodeDotAttrs.label.value:
NodeDotLabelUtils.formatLabel(self.toPlainText())
}
# Update text in other views
node = self.parentItem()
node.graphicsGraphView.controller.onEditNode(node.id, dicDotAttrs)
# Disable edit text
self.setTextInteractionFlags(Qt.NoTextInteraction)
# Label is invalid: force user to write a correct label
else:
QMessageBox.warning(None, "Syntax error",
"The label is invalid.")
self.setFocus()
示例3: ActionItem
class ActionItem(GraphicsItem):
def __init__(self, model_item: SimulatorItem, parent=None):
super().__init__(model_item=model_item, parent=parent)
self.setFlag(QGraphicsTextItem.ItemIsPanel, True)
self.text = QGraphicsTextItem(self)
self.text.setFont(self.font)
def update_flags(self):
if self.scene().mode == 0:
self.set_flags(is_selectable=True, is_movable=True, accept_hover_events=True, accept_drops=True)
def update_position(self, x_pos, y_pos):
self.setPos(x_pos, y_pos)
start_x = (self.scene().items_width() - self.labels_width()) / 2
self.number.setPos(start_x, 0)
start_x += self.number.boundingRect().width()
self.text.setPos(start_x, 0)
width = self.scene().items_width()
self.prepareGeometryChange()
self.bounding_rect = QRectF(0, 0, width, self.childrenBoundingRect().height() + 5)
def labels_width(self):
width = self.number.boundingRect().width()
width += self.text.boundingRect().width()
return width
示例4: keyPressEvent
def keyPressEvent(self, event):
'''Handle key pressed event.
Argument(s):
event (QKeyEvent): Key event
'''
QGraphicsTextItem.keyPressEvent(self, event)
self.parentItem().updateShapeAndEdges()
示例5: mousePressEvent
def mousePressEvent(self, e):
modifiers = QApplication.keyboardModifiers()
if modifiers == Qt.ControlModifier:
e.ignore()
else:
for item in self.scene().selectedItems():
item.setSelected(False)
QGraphicsTextItem.mousePressEvent(self, e)
示例6: setPlainText
def setPlainText(self, text):
'''Sets the item's text to text.
Argument(s):
text (str): New text
'''
QGraphicsTextItem.setPlainText(self, text)
self.parentItem().updateShapeAndEdges()
示例7: __init__
def __init__(self, model_item: SimulatorRuleCondition, parent=None):
assert isinstance(model_item, SimulatorRuleCondition)
super().__init__(model_item=model_item, parent=parent)
self.number.setFont(self.font_bold)
self.text = QGraphicsTextItem(self)
self.text.setPlainText(self.model_item.type.value)
self.text.setFont(self.font_bold)
self.desc = QGraphicsTextItem(self)
self.desc.setFont(self.font)
示例8: __init__
def __init__(self, model_item: SimulatorItem, parent=None):
super().__init__(model_item=model_item, parent=parent)
self.setFlag(QGraphicsTextItem.ItemIsPanel, True)
self.text = QGraphicsTextItem(self)
self.text.setFont(self.font)
示例9: addGraphicsItems
def addGraphicsItems(self):
self.mainRect = QGraphicsRectItem(QRectF(-15, -15, 30, 30), self)
self.nodeTitle = QGraphicsTextItem(type(self).name, self)
titleFont = QFont()
titleFont.setBold(True)
self.nodeTitle.setFont(titleFont)
self.selectedChanged(self.isSelected())
示例10: __init__
def __init__(self, parent=None):
QGraphicsView.__init__(self, parent)
self.updateSecs = 0.5
# Border
self.setLineWidth(0)
self.setFrameShape(QtWidgets.QFrame.NoFrame)
# Size
sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
sizePolicy.setHeightForWidth(True)
self.setSizePolicy(sizePolicy)
# No scrollbars
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
# Scene
self.scene = QGraphicsScene()
self.setScene(self.scene)
self.setBackgroundBrush(QColor("black"))
# Text of clock
self.textItem = QGraphicsTextItem()
self.textItem.color = QColor(QColor("black"))
self.textItem.setFont(QFont("Segoe UI", 80))
self.textItem.setDefaultTextColor(QColor("white"))
self.textItem.setHtml("")
self.textItem.setZValue(20)
self.scene.addItem(self.textItem)
# Start ticking
self.start()
示例11: _setupTextItem
def _setupTextItem(self):
#Set up the text
self.textItem=QGraphicsTextItem("",parent=self)
textItem=self.textItem
font=QFont()
font.setPointSize(self._fontSize)
textItem.setFont(font)
textItem.setPos(QPointF(0,0)) #upper left corner relative to the father
textItem.setDefaultTextColor(self._fontColor)
if self._dbg:
#another text item only for debug
self.textItemBottom=QGraphicsTextItem("",parent=self)
self.textItemBottom.setPos(QPointF(self.width,self.height))
self.textItemBottom.setDefaultTextColor(QColor(255, 255, 255))
self._updateTextBottom("shape " +str(self.shape))
示例12: __init__
def __init__(self, model_item: SimulatorMessage, parent=None):
assert isinstance(model_item, SimulatorMessage)
super().__init__(model_item=model_item, parent=parent)
self.setFlag(QGraphicsItem.ItemIsPanel, True)
self.arrow = MessageArrowItem(self)
self.repeat_text = QGraphicsTextItem(self)
self.repeat_text.setFont(self.font)
示例13: __init__
def __init__(self, model_item: Participant, parent=None):
super().__init__(parent)
self.model_item = model_item
self.text = QGraphicsTextItem(self)
self.line = QGraphicsLineItem(self)
self.line.setPen(QPen(Qt.darkGray, 1, Qt.DashLine, Qt.RoundCap, Qt.RoundJoin))
self.refresh()
示例14: __init__
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())
示例15: reshape
def reshape(self):
''' Update the shape of the edge (redefined function) '''
path = QPainterPath()
# If there is a starting point, draw a line to the first curve point
if self.start_point:
path.moveTo(self.source_connection.center)
path.lineTo(self.bezier[0])
else:
path.moveTo(self.source_connection.center)
# Loop over the curve points:
for group in self.bezier[1:]:
path.cubicTo(*[point.center for point in group])
# If there is an ending point, draw a line to it
if self.end_point:
path.lineTo(self.end_connection.center)
end_point = path.currentPosition()
arrowhead = self.angle_arrow(path)
path.lineTo(arrowhead[0])
path.moveTo(end_point)
path.lineTo(arrowhead[1])
path.moveTo(end_point)
try:
# Add the transition label, if any (none for the START edge)
font = QFont('arial', pointSize=8)
metrics = QFontMetrics(font)
label = self.edge.get('label', '')
lines = label.split('\n')
width = metrics.width(max(lines)) # longest line
height = metrics.height() * len(lines)
# lp is the position of the center of the text
pos = self.mapFromScene(*self.edge['lp'])
if not self.text_label:
self.text_label = QGraphicsTextItem(
self.edge.get('label', ''), parent=self)
self.text_label.setX(pos.x() - width / 2)
self.text_label.setY(pos.y() - height / 2)
self.text_label.setFont(font)
# Make horizontal center alignment, as dot does
self.text_label.setTextWidth(self.text_label.boundingRect().width())
fmt = QTextBlockFormat()
fmt.setAlignment(Qt.AlignHCenter)
cursor = self.text_label.textCursor()
cursor.select(QTextCursor.Document)
cursor.mergeBlockFormat(fmt)
cursor.clearSelection()
self.text_label.setTextCursor(cursor)
self.text_label.show()
except KeyError:
# no label
pass
self.setPath(path)