本文整理汇总了Python中PyQt5.QtWidgets.QGraphicsTextItem.setPos方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsTextItem.setPos方法的具体用法?Python QGraphicsTextItem.setPos怎么用?Python QGraphicsTextItem.setPos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QGraphicsTextItem
的用法示例。
在下文中一共展示了QGraphicsTextItem.setPos方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addWP
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPos [as 别名]
def addWP(self, wp):
if wp.command in [mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,
mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,
mavutil.mavlink.MAV_CMD_NAV_LOITER_TO_ALT,
mavutil.mavlink.MAV_CMD_NAV_LOITER_TURNS,
mavutil.mavlink.MAV_CMD_NAV_LOITER_TIME,
mavutil.mavlink.MAV_CMD_NAV_LOITER_UNLIM,
mavutil.mavlink.MAV_CMD_NAV_LAND]:
#point
rad = self.__wp_diameter * 0.5
ellipse = QGraphicsEllipseItem(wp.y - rad, -wp.x - rad,
self.__wp_diameter, self.__wp_diameter, self.__mission_layer)
ellipse.setBrush(QBrush(QColor(255, 255, 255)))
e_pen = QPen(QColor(255, 255, 255))
e_pen.setWidth(0)
ellipse.setPen(e_pen)
self.__mission_layer.addToGroup(ellipse)
#label
label = QGraphicsTextItem(str(wp.seq), self.__mission_layer)
label.setZValue(2)
label.setDefaultTextColor(Qt.white)
label.setPos(wp.y + rad, -wp.x - rad)
label.setScale(0.00002) #bit hacky -- really should scale based on
#current zoom, but I'm in a hurry.
self.__mission_layer.addToGroup(label)
label.show()
示例2: ActionItem
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPos [as 别名]
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
示例3: showImage
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPos [as 别名]
def showImage(self):
(newImg, newImgInfo) = self.loadImage()
# return PicItem(Pixmap(QPixmap(newImg)), -1, -1, xFactor, yFactor, newImgInfo)
self.scene.clear()
imgSz = newImgInfo.imgSize
self.setSceneRect(QRectF(0,0,imgSz.width(), imgSz.height()))
pixMap = QPixmap.fromImage(newImg)
# # pixMap.setWidth(self.width())
pixMapItem = self.scene.addPixmap(pixMap)
# pixMapItem.setPos(50,50)
# self.fitInView(QRectF(0, 0, self.width(), self.height()), Qt.KeepAspectRatio)
# Add caption
caption = QGraphicsTextItem()
caption.setDefaultTextColor(QColor(255,255,255))
caption.setPos(0, self.height()*0.94)
caption.setFont(QFont("Segoe UI", 30))
caption.setTextWidth(self.width())
# caption.setPos(100, 100)
# caption.setTextWidth(1500)
# if newImgInfo.createDate is not None:
# caption.setPlainText(newImgInfo.createDate.format());
# else:
# caption.setPlainText("Image is called bananas");
# print("Tags", newImgInfo.tags)
# tagStr = ""
# for tag in newImgInfo.tags:
# if tag != "Duplicate":
# tagStr += (", " if len(tagStr) != 0 else "") + tag
# if tagStr == "":
# tagStr = "NO TAGS"
# captionStr = '<h1 style="text-align:center;width:100%">' + tagStr + '</h1>'
# if newImgInfo.createDate is not None:
# print(newImgInfo.createDate.format())
# captionStr += '<BR><h2>' + newImgInfo.createDate.format() + '</h2>'
captionStr = ""
try:
if newImgInfo.rating is not None:
for i in range(newImgInfo.rating):
captionStr += "★"
for i in range(5-newImgInfo.rating):
captionStr += "☆"
if newImgInfo.mainDate is not None:
if len(captionStr) != 0:
captionStr += " "
captionStr += newImgInfo.mainDate.strftime("%d %b %Y")
except Exception as excp:
print("StaticPhotos: Cannot set caption")
captionStr = '<div style="background-color:#000000;text-align: right;padding-right:10dp;">' + captionStr + "</div>"
print(captionStr)
caption.setHtml(captionStr)
self.scene.addItem(caption)
self.scene.update()
示例4: set_functions_list
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPos [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
示例5: ParticipantItem
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPos [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
示例6: create_map_points
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPos [as 别名]
def create_map_points(self):
self.map_points_text_items = []
self.map_points_items = []
for map_point in self.map_data.map_points:
color = QColor().fromRgb(map_point.r, map_point.g, map_point.b)
rect = QGraphicsRectItem(
QRectF(
QPointF(map_point.x, map_point.y),
QSizeF(5 / self.scale_ratio, 5 / self.scale_ratio)
)
)
rect.setPen(QPen(Qt.black, 1 / self.scale_ratio))
rect.setBrush(color)
self.map_points_items.append(rect)
text = QGraphicsTextItem(map_point.text)
text.setDefaultTextColor(color)
text.setPos(map_point.x, map_point.y)
text.setFont(QFont('Times New Roman', 8 / self.scale_ratio, 2))
self.map_points_text_items.append(text)
示例7: drawAxis
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPos [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
示例8: define
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPos [as 别名]
def define(self, cells):
index = 0
cell_sum = 0
for y in range(self.height):
for x in range(self.width):
try:
required_bridges = int(cells[y][x])
new_island = Island(index, x, y, required_bridges)
self.islands.append(new_island)
self.grid[y][x] = new_island
text_item = QGraphicsTextItem(str(required_bridges))
text_item.setFont(self.font)
text_item.setPos(30*x+5, 30*y-2)
self.scene.addItem(text_item)
cell_sum += required_bridges
index += 1
except ValueError:
pass
if cell_sum % 2 == 0:
self.total_required_bridges = int(cell_sum / 2)
print("Found {} islands that require a total of {} bridges".format(index, self.total_required_bridges))
else:
print("The grid is not valid!")
示例9: QGraphicsScene
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPos [as 别名]
"<p>"
"Tell the stickman what to do!"
"</p>"
"<p><i>"
'<li>Press <font color="purple">J</font> to make the stickman jump.</li>'
'<li>Press <font color="purple">D</font> to make the stickman dance.</li>'
'<li>Press <font color="purple">C</font> to make him chill out.</li>'
'<li>When you are done, press <font color="purple">Escape</font>.</li>'
"</i></p>"
"<p>If he is unlucky, the stickman will get struck by lightning, and never jump, dance or chill out again."
"</p></font>"
)
w = textItem.boundingRect().width()
stickManBoundingRect = stickMan.mapToScene(stickMan.boundingRect()).boundingRect()
textItem.setPos(-w / 2.0, stickManBoundingRect.bottom() + 25.0)
scene = QGraphicsScene()
scene.addItem(stickMan)
scene.addItem(textItem)
scene.setBackgroundBrush(Qt.black)
view = GraphicsView()
view.setRenderHints(QPainter.Antialiasing)
view.setTransformationAnchor(QGraphicsView.NoAnchor)
view.setScene(scene)
view.show()
view.setFocus()
# Make enough room in the scene for stickman to jump and die.
sceneRect = scene.sceneRect()
示例10: TcamScreen
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPos [as 别名]
#.........这里部分代码省略.........
if self.image_counter == 1:
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():
示例11: MessageItem
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPos [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
#.........这里部分代码省略.........
示例12: QGraphicsResizableRect
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPos [as 别名]
#.........这里部分代码省略.........
self._fontSize=s
font=QFont()
font.setPointSize(self._fontSize)
self.textItem.setFont(font)
self.updateText(self.textItem.toPlainText())
@property
def lineWidth(self):
return self._lineWidth
@pyqtSlot(int)
def setLineWidth(self,s):
self._lineWidth=s
self.updateColor()
@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()
示例13: RuleConditionItem
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPos [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)
#.........这里部分代码省略.........
示例14: Node
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setPos [as 别名]
class Node(QGraphicsRectItem):
class io(QGraphicsRectItem):
class BezierCurve(QGraphicsPathItem):
def __init__(self, iostart=None, ioend=None):
super().__init__()
self.setEnabled(False) # Make it ignore events. Links can't be interacted with.
self.iostart = iostart
self.ioend = ioend
if iostart is not None and ioend is not None:
self.update()
else:
self.update(QPointF(0, 0))
def update(self, pos=None):
path = QPainterPath()
if pos is not None:
if self.ioend is None:
startpos = self.iostart.pos() + self.iostart.parent.pos()
endpos = pos
elif self.iostart is None:
startpos = pos
endpos = self.ioend.pos() + self.ioend.parent.pos()
else:
startpos = self.iostart.pos() + self.iostart.parent.pos()
endpos = self.ioend.pos() + self.ioend.parent.pos()
controlpoint = QPointF(abs((endpos - startpos).x()) * 0.8, 0)
path.moveTo(startpos)
path.cubicTo(startpos + controlpoint,
endpos - controlpoint,
endpos)
self.setPath(path)
def __init__(self, parent, index, iotype, iodir):
self.parent = parent
self.index = index
self.iotype = iotype
self.iodir = iodir
super().__init__(-8, -8, 16, 16, self.parent) # Size of io-boxes is 16x16
self.setAcceptHoverEvents(True)
self.iobrush = QBrush(QColor(70, 70, 70, 255))
self.setBrush(self.iobrush)
self.newbezier = None # Variable for temporary storage of bezier curve while it's still being dragged
self.bezier = []
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
if self.iodir == "output":
self.newbezier = Node.io.BezierCurve(self, None)
elif self.iodir == "input":
self.newbezier = Node.io.BezierCurve(None, self)
if self.newbezier is not None:
self.newbezier.update(QPointF(event.pos() + self.pos() + self.parent.pos()))
self.parent.parent.scene.addItem(self.newbezier)
elif event.button() == Qt.RightButton:
self.delAllBezier()
def mouseMoveEvent(self, event):
if self.newbezier is not None:
self.newbezier.update(QPointF(event.pos() + self.pos() + self.parent.pos()))
def mouseReleaseEvent(self, event):
if self.newbezier is not None:
self.parent.parent.scene.removeItem(self.newbezier)
self.newbezier = None
# Find out if an io box lies under the cursor
pos = event.pos() + self.pos() + self.parent.pos()
pos = self.parent.parent.mapFromScene(pos)
target = self.parent.parent.itemAt(pos.x(), pos.y())
# If io box is found, spawn a bezier curve
if target is None:
if self.iodir == "output":
ns = NodeSelector(self.parent.parent.modman, modfilter={"type": {"type": self.iotype, "dir": "input"}})
elif self.iodir == "input":
ns = NodeSelector(self.parent.parent.modman, modfilter={"type": {"type": self.iotype, "dir": "output"}})
if ns.exec():
if issubclass(ns.data["node"], baseModule.BaseNode):
newNode = Node(self.parent.parent, ns.data["node"])
newNode.setPos(event.pos() + self.pos() + self.parent.pos())
self.parent.parent.scene.addItem(newNode)
if self.iodir == "output":
target = newNode.inputIO[ns.data["pin"]]
elif self.iodir == "input":
target = newNode.outputIO[ns.data["pin"]]
if target is not None and isinstance(target, Node.io):
bezier = None
#.........这里部分代码省略.........