本文整理汇总了Python中PyQt5.QtWidgets.QGraphicsTextItem.setPlainText方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsTextItem.setPlainText方法的具体用法?Python QGraphicsTextItem.setPlainText怎么用?Python QGraphicsTextItem.setPlainText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QGraphicsTextItem
的用法示例。
在下文中一共展示了QGraphicsTextItem.setPlainText方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setPlainText
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPlainText [as 别名]
def setPlainText(self, text):
'''Sets the item's text to text.
Argument(s):
text (str): New text
'''
QGraphicsTextItem.setPlainText(self, text)
self.parentItem().updateShapeAndEdges()
示例2: set_functions_list
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPlainText [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: ParticipantItem
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPlainText [as 别名]
class ParticipantItem(QGraphicsItem):
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()
def update_position(self, x_pos=-1, y_pos=-1):
if x_pos == -1:
x_pos = self.x_pos()
if y_pos == -1:
y_pos = self.line.line().y2()
self.text.setPos(x_pos - (self.text.boundingRect().width() / 2), 0)
self.line.setLine(x_pos, 30, x_pos, y_pos)
def x_pos(self):
return self.line.line().x1()
def width(self):
return self.boundingRect().width()
def refresh(self):
self.text.setPlainText("?" if not self.model_item else self.model_item.shortname)
if hasattr(self.model_item, "simulate") and self.model_item.simulate:
font = QFont()
font.setBold(True)
self.text.setFont(font)
self.text.setDefaultTextColor(Qt.darkGreen)
self.line.setPen(QPen(Qt.darkGreen, 2, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
else:
self.text.setFont(QFont())
self.text.setDefaultTextColor(constants.LINECOLOR)
self.line.setPen(QPen(Qt.darkGray, 1, Qt.DashLine, Qt.RoundCap, Qt.RoundJoin))
def boundingRect(self):
return self.childrenBoundingRect()
def paint(self, painter, option, widget):
pass
示例4: drawAxis
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPlainText [as 别名]
def drawAxis(self, data, points):
xmin = data['xmin']
xmax = data['xmax']
ymin = data['ymin']
ymax = data['ymax']
xmarg = data['xmarg']
ymarg = data['xmarg']
xscale = data['xscale']
yscale = data['yscale']
scene = self.uiFunctionGraph.scene()
scene.addLine(xmarg - 10, ymarg + 10, (xmax - xmin) * xscale + xmarg + 10, ymarg + 10)
scene.addLine((xmax - xmin) * xscale + xmarg + 8, ymarg + 8, (xmax - xmin) * xscale + xmarg + 10, ymarg + 10)
scene.addLine((xmax - xmin) * xscale + xmarg + 8, ymarg + 13, (xmax - xmin) * xscale + xmarg + 10, ymarg + 11)
scene.addLine(xmarg - 10, ymarg + 10, xmarg - 10, (ymax - ymin) * yscale + ymarg - 10)
scene.addLine(xmarg - 8, (ymax - ymin) * yscale + ymarg - 9, xmarg - 10, (ymax - ymin) * yscale + ymarg - 11)
scene.addLine(xmarg - 12, (ymax - ymin) * yscale + ymarg - 8, xmarg - 10, (ymax - ymin) * yscale + ymarg - 10)
y = ymin
step = (ymax - ymin) / 4
for i in range(5):
scene.addLine(xmarg - 12, (y - ymin) * yscale + ymarg, xmarg - 8, (y - ymin) * yscale + ymarg)
text = QGraphicsTextItem()
text.setPos(0, (y - ymin) * yscale + ymarg - 7)
text.setPlainText('%s' % format(round(y, 3), '.3f'))
text.setFont(QFont('Sans', 6))
scene.addItem(text)
y += step
x = xmin
step = (xmax - xmin) / 19
for i in range(20):
scene.addLine((x - xmin) * xscale + xmarg, ymarg + 8, (x - xmin) * xscale + xmarg, ymarg + 12)
text = QGraphicsTextItem()
text.setPos((x - xmin) * xscale + xmarg - 14, ymarg + 10)
text.setPlainText('%s' % format(round(x, 3), '.3f'))
text.setFont(QFont('Sans', 6))
scene.addItem(text)
x += step
示例5: TcamScreen
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPlainText [as 别名]
#.........这里部分代码省略.........
self.resize(self.size())
self.scene.setSceneRect(self.pix.boundingRect())
self.update()
self.reset_zoom()
self.first_image = False
# wait for the second image
# resizeEvents, etc appear before the scene has adjusted
# to the actual image size. By waiting for the 2. image
# we circumvent this by having the first image making all
# adjustments for us. The only scenario where this will
# cause problems is triggering.
if self.is_fullscreen and self.image_counter == 2:
self.fit_view()
self.send_mouse_pixel()
# don't call repaint here
# it causes problems once the screen goes blank due to screensavers, etc
# self.repaint()
def wait_for_first_image(self):
if not self.display_real_image:
return
self.reset_zoom()
self.display_real_image = False
self.text_item = QGraphicsTextItem()
self.text_item.setDefaultTextColor(QColor("white"))
self.text_item.setPos(100, 70)
self.text_item.setPlainText("In Trigger Mode. Waiting for first image...")
bg = QPixmap(1280, 720)
bg.fill(QColor("grey"))
self.pix.setPixmap(bg)
self.image_counter += 1
self.scene.addItem(self.text_item)
def send_mouse_pixel(self):
# mouse positions start at 0
# we want the lower right corner to have the correct coordinates
# e.g. an 1920x1080 image should have the coordinates
# 1920x1080 for the last pixel
self.new_pixel_under_mouse.emit(self.pix.legal_coordinates(self.mouse_position_x,
self.mouse_position_y),
self.mouse_position_x + 1,
self.mouse_position_y + 1,
self.pix.get_color_at_position(self.mouse_position_x,
self.mouse_position_y))
def mouseMoveEvent(self, event):
mouse_position = self.mapToScene(event.pos())
self.mouse_position_x = mouse_position.x()
self.mouse_position_y = mouse_position.y()
if self.selection_area:
# adjust rect since we want to pull in all directions
# origin can well be bottom left, thus recalc
def calc_selection_rect():
x = min(self.origin.x(), event.pos().x())
示例6: OcrArea
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPlainText [as 别名]
class OcrArea(QGraphicsRectItem):
## static data
resizeBorder = .0
def __init__(self, pos, size, type_, parent = None, scene = None,
areaBorder = 2, index = 0, textSize = 50):
QGraphicsRectItem.__init__(self, 0, 0, size.width(), size.height(),
parent)
self.setPos(pos)
self.newEvent = IsClicked()
self.newEvent.area = self
#self.setAcceptedMouseButtons(QtCore.Qt.NoButton)
self.setFlags(QGraphicsItem.ItemIsMovable |
QGraphicsItem.ItemIsFocusable |
QGraphicsItem.ItemIsSelectable)
## set index label
self.text = QGraphicsTextItem("%d" % index, self)
self.setTextSize(textSize)
## TODO: How to create constants for the type?
## (such as constants in Qt) (enum?)
self.kind = type_
pen = QPen(self.color, areaBorder, Qt.SolidLine,
Qt.RoundCap, Qt.RoundJoin)
self.setPen(pen)
# self.setAcceptsHoverEvents(True) # TODO
# self.text.setFlag(QtGui.QGraphicsItem.ItemIgnoresTransformations)
def setIndex(self, idx):
self.text.setPlainText(str(idx))
def setTextSize(self, size):
font = QFont()
font.setPointSizeF(size)
self.text.setFont(font)
def contextMenuEvent(self, event):
menu = QMenu()
removeAction = menu.addAction(QA.translate('QOcrWidget', "Remove"))
#Action = menu.addAction(self.scene().tr("Remove"))
menu.addSeparator()
textAction = menu.addAction(QA.translate('QOcrWidget', "Text"))
graphicsAction = menu.addAction(QA.translate('QOcrWidget', "Graphics"))
## verification of the type of the selection and
## setting a check box near the type that is in use
textAction.setCheckable(True)
graphicsAction.setCheckable(True)
if self.kind == 1:
textAction.setChecked(True)
elif self.kind == 2:
graphicsAction.setChecked(True)
selectedAction = menu.exec_(event.screenPos())
if selectedAction == removeAction:
self.scene().removeArea(self)
elif selectedAction == textAction:
self.kind = 1
elif selectedAction == graphicsAction:
self.kind = 2
# when the area is selected the signal "isClicked()" is raised
def mousePressEvent(self, event):
self.newEvent.isClicked.emit()
QGraphicsRectItem.mousePressEvent(self, event)
# type property
def _setType(self, type_):
self.__type = type_
if self.__type == 1:
self.color = Qt.darkGreen
else: ## TODO: else -> elif ... + else raise exception
self.color = Qt.blue
self.text.setDefaultTextColor(self.color)
pen = self.pen()
pen.setColor(self.color)
self.setPen(pen)
def _type(self):
return self.__type
kind = property(fget=_type, fset=_setType)
示例7: MessageItem
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPlainText [as 别名]
class MessageItem(GraphicsItem):
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)
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 width(self):
labels = self.labels()
width = self.number.boundingRect().width()
# width += 5
width += sum([lbl.boundingRect().width() for lbl in labels])
width += 5 * (len(labels) - 1)
width += self.repeat_text.boundingRect().width()
return width
def refresh(self):
self.repeat_text.setPlainText("(" + str(self.model_item.repeat) + "x)" if self.model_item.repeat > 1 else "")
def labels(self):
self.refresh_unlabeled_range_marker()
unlabeled_range_items = [uri for uri in self.childItems() if isinstance(uri, UnlabeledRangeItem)]
result = []
start = 0
i = 0
message = self.model_item
if len(message) and not message.message_type:
result.append(unlabeled_range_items[0])
else:
for lbl in message.message_type:
if lbl.start > start:
result.append(unlabeled_range_items[i])
i += 1
result.append(self.scene().model_to_scene(lbl))
start = lbl.end
if start < len(message):
result.append(unlabeled_range_items[i])
return result
def refresh_unlabeled_range_marker(self):
msg = self.model_item
urm = [item for item in self.childItems() if isinstance(item, UnlabeledRangeItem)]
if len(msg):
num_unlabeled_ranges = len(msg.message_type.unlabeled_ranges)
if msg.message_type and msg.message_type[-1].end >= len(msg):
num_unlabeled_ranges -= 1
else:
num_unlabeled_ranges = 0
if len(urm) < num_unlabeled_ranges:
for i in range(num_unlabeled_ranges - len(urm)):
UnlabeledRangeItem(self)
else:
for i in range(len(urm) - num_unlabeled_ranges):
self.scene().removeItem(urm[i])
def update_position(self, x_pos, y_pos):
labels = self.labels()
self.setPos(QPointF(x_pos, y_pos))
p_source = self.mapFromItem(self.source.line, self.source.line.line().p1())
p_destination = self.mapFromItem(self.destination.line, self.destination.line.line().p1())
arrow_width = abs(p_source.x() - p_destination.x())
start_x = min(p_source.x(), p_destination.x())
start_x += (arrow_width - self.width()) / 2
start_y = 0
self.number.setPos(start_x, start_y)
start_x += self.number.boundingRect().width()
for label in labels:
label.setPos(start_x, start_y)
start_x += label.boundingRect().width() + 5
self.repeat_text.setPos(start_x, start_y)
if labels:
start_y += labels[0].boundingRect().height() + 5
else:
start_y += 26
#.........这里部分代码省略.........
示例8: QGraphicsResizableRect
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPlainText [as 别名]
#.........这里部分代码省略.........
@property
def color(self):
return self._normalColor
@pyqtSlot(int)
def setColor(self,qcolor):
self._normalColor=qcolor
self.updateColor()
@pyqtSlot()
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))
@pyqtSlot(str)
def _updateTextBottom(self,string):
self.textItemBottom.setPlainText(string)
def setNewSize(self, constrainAxis, size, flip=False):
if constrainAxis == 0:
h,w = size, self.rect().width()
else:
h,w = self.rect().height(), size
if flip and constrainAxis ==0:
w=-w
if flip and constrainAxis ==1:
h=-h
newrect=QRectF(0, 0, w, h).normalized()
self.setRect(newrect)
self.width=self.rect().width()
self.height=self.rect().height()
self.shape=(self.height,self.width)
#Ensures that the text is in the upper left corner
a=0
b=0
if w<=0: a=w
if h<=0: b=h
self.textItem.setPos(QPointF(a,b))
if self._dbg:
self.textItemBottom.setPos(QPointF(self.width,self.height))
for el in self._resizeHandles:
#print "shape = %s , left = %s , right = %s , top = %s , bottm , %s "%(self.shape,self.rect().left(),self.rect().right(),self.rect().top(),self.rect().bottom())
示例9: RuleConditionItem
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPlainText [as 别名]
class RuleConditionItem(GraphicsItem):
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)
def update_flags(self):
if self.scene().mode == 0:
self.set_flags(is_selectable=True, accept_hover_events=True, accept_drops=True)
else:
self.set_flags(is_selectable=True, accept_hover_events=True)
def labels_width(self):
return max(self.number.boundingRect().width() + self.text.boundingRect().width(),
self.desc.boundingRect().width())
def refresh(self):
if len(self.model_item.condition):
if len(self.model_item.condition) > 20:
self.desc.setPlainText(self.model_item.condition[:20] + "...")
else:
self.desc.setPlainText(self.model_item.condition)
elif self.model_item.type != ConditionType.ELSE:
self.desc.setPlainText("<Condition>")
def update_position(self, x_pos, y_pos):
self.setPos(x_pos, y_pos)
start_y = 0
start_x = ((self.scene().items_width() + 40) - (
self.number.boundingRect().width() + self.text.boundingRect().width())) / 2
self.number.setPos(start_x, start_y)
start_x += self.number.boundingRect().width()
self.text.setPos(start_x, start_y)
start_y += round(self.number.boundingRect().height())
start_x = ((self.scene().items_width() + 40) - self.desc.boundingRect().width()) / 2
self.desc.setPos(start_x, start_y)
if self.model_item.type != ConditionType.ELSE:
start_y += round(self.desc.boundingRect().height())
start_y += 5
for child in self.get_scene_children():
child.update_position(20, start_y)
start_y += round(child.boundingRect().height())
width = self.scene().items_width()
self.prepareGeometryChange()
self.bounding_rect = QRectF(0, 0, width + 40, self.childrenBoundingRect().height() + 5)
def update_drop_indicator(self, pos):
rect = self.boundingRect()
if pos.y() - rect.top() < rect.height() / 3:
self.drop_indicator_position = QAbstractItemView.AboveItem
elif rect.bottom() - pos.y() < rect.height() / 3:
self.drop_indicator_position = QAbstractItemView.BelowItem
else:
self.drop_indicator_position = QAbstractItemView.OnItem
self.update()
def paint(self, painter, option, widget):
if self.scene().mode == 1:
self.setOpacity(1 if self.model_item.logging_active else 0.3)
painter.setOpacity(constants.SELECTION_OPACITY)
if self.hover_active or self.isSelected():
painter.setBrush(constants.SELECTION_COLOR)
elif not self.is_valid():
painter.setBrush(QColor(255, 0, 0, 150))
else:
painter.setBrush(QColor.fromRgb(204, 204, 204, 255))
height = self.number.boundingRect().height()
if self.model_item.type != ConditionType.ELSE:
height += self.desc.boundingRect().height()
painter.drawRect(QRectF(0, 0, self.boundingRect().width(), height))
painter.setBrush(Qt.NoBrush)
painter.drawRect(self.boundingRect())
if self.drag_over:
self.paint_drop_indicator(painter)
def paint_drop_indicator(self, painter):
painter.setPen(QPen(Qt.darkRed, 2, Qt.SolidLine))
painter.setBrush(Qt.NoBrush)
#.........这里部分代码省略.........
示例10: ClassModel
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPlainText [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()