本文整理汇总了Python中PyQt4.QtGui.QGraphicsSimpleTextItem.setParentItem方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsSimpleTextItem.setParentItem方法的具体用法?Python QGraphicsSimpleTextItem.setParentItem怎么用?Python QGraphicsSimpleTextItem.setParentItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QGraphicsSimpleTextItem
的用法示例。
在下文中一共展示了QGraphicsSimpleTextItem.setParentItem方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyQt4.QtGui import QGraphicsSimpleTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsSimpleTextItem import setParentItem [as 别名]
def __init__(self, table, vector, mass=1.0):
"""Documentation here"""
self.name = table.name
self._mediator = Mediator()
# layout widget
x, y = vector.x, vector.y
text = QGraphicsSimpleTextItem('{0} as {1}'.format(self.name, self.alias))
width = text.boundingRect().width()
QGraphicsRectItem.__init__(self, x, y, width + 10, 22)
self.table = table.alias(self.alias)
self.setBrush(Qt.cyan)
self.setPen(Qt.darkCyan)
self.width = width + 10
self.height = 22
self.setFlag(self.ItemIsSelectable, True)
text.setParentItem(self)
text.setX(x + 5)
text.setY(y + 5)
self.point = vector
self.mass = mass
self.velocity = Vector(0, 0)
self.force = Vector(0, 0)
self.instances.append(self)
示例2: iLabel
# 需要导入模块: from PyQt4.QtGui import QGraphicsSimpleTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsSimpleTextItem import setParentItem [as 别名]
def iLabel(node, *args, **kargs):
#code for making specialized faces for intermediates mostly cribbed from the ete2 website example (though not interactive):
# http://pythonhosted.org/ete2/tutorial/tutorial_drawing.html#creating-your-custom-interactive-item-faces
my_label = node.name
ellipse = QGraphicsEllipseItem(0,0,fontSize*2,fontSize*2) #I think the first two are coords of center; second pair is major/minor axis
ellipse.setPen(QPen(QColor( 'black' )))
ellipse.setBrush(QBrush(QColor( 'white' )))
text = QGraphicsSimpleTextItem(my_label)
text.setParentItem(ellipse)
text.setBrush(QBrush(QColor("black")))
font = QFont("Arial",fontSize*.9,weight=80)
font.setLetterSpacing(1, 2) #add 2 pixels between letters for legibility
text.setFont(font)
#Center text according to masterItem size
tw = text.boundingRect().width()
th = text.boundingRect().height()
center = ellipse.boundingRect().center()
text.setPos(center.x()+1-tw/2, center.y()-th/2) #since the last letter has an extra 2 pixels after it from the spacing command, adjust center to compensate
return ellipse
示例3: draw_y_axis
# 需要导入模块: from PyQt4.QtGui import QGraphicsSimpleTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsSimpleTextItem import setParentItem [as 别名]
def draw_y_axis(self):
lineItem = QGraphicsLineItem(0, self.coordY(self.ylim[0]),
0, self.coordY(self.ylim[1]),
parent=self.item)
lineItem.setPen(QPen(QColor('black')))
lineItem.setZValue(10)
max_w = 0
for y in set(self.hlines + list(self.ylim)):
lineItem = QGraphicsLineItem(0, self.coordY(y),
-5, self.coordY(y),
parent=self.item)
lineItem.setPen(QPen(QColor('black')))
lineItem.setZValue(10)
text = QGraphicsSimpleTextItem(str(y))
text.setFont(QFont("Arial", self.fsize-2))
text.setParentItem(self.item)
tw = text.boundingRect().width()
max_w = tw if tw > max_w else max_w
th = text.boundingRect().height()
# Center text according to masterItem size
text.setPos(-tw - 5, self.coordY(y)-th/2)
if self.ylabel:
text = QGraphicsSimpleTextItem(self.ylabel)
text.setFont(QFont("Arial", self.fsize-1))
text.setParentItem(self.item)
text.rotate(-90)
tw = text.boundingRect().width()
th = text.boundingRect().height()
# Center text according to masterItem size
text.setPos(-th -5-max_w, tw/2+self.coordY(sum(self.ylim)/2))
示例4: draw_x_axis
# 需要导入模块: from PyQt4.QtGui import QGraphicsSimpleTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsSimpleTextItem import setParentItem [as 别名]
def draw_x_axis(self):
#lineItem = QGraphicsLineItem(self.col_w/2,
# self.coordY(self.ylim[0])+2,
# self.width-self.col_w/2,
# self.coordY(self.ylim[0])+2,
# parent=self.item)
#lineItem.setPen(QPen(QColor('black')))
#lineItem.setZValue(10)
#all_vals = list(range(0, len(self.values), 5))
#if (len(self.values)-1)%5:
# all_vals += [len(self.values)-1]
for x, lab in enumerate(self.values):
# lineItem = QGraphicsLineItem(0, self.coordY(self.ylim[0])+2,
# 0, self.coordY(self.ylim[0])+6,
# parent=self.item)
# lineItem.setX(x*self.col_w + self.col_w/2)
# lineItem.setPen(QPen(QColor('black')))
# lineItem.setZValue(10)
text = QGraphicsSimpleTextItem(str(lab))
text.rotate(-90)
text.setFont(QFont("Arial", self.fsize-2))
text.setParentItem(self.item)
tw = text.boundingRect().height()
# Center text according to masterItem size
text.setPos(x*self.col_w-tw/2 + self.col_w/2,
self.coordY(self.ylim[0]))
示例5: add_text
# 需要导入模块: from PyQt4.QtGui import QGraphicsSimpleTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsSimpleTextItem import setParentItem [as 别名]
def add_text(self):
if (self.labels):
center = self.item.boundingRect().center()
text = QGraphicsSimpleTextItem(str(self.labels))
text.setFont(QFont("Arial", self.label_size))
text.setParentItem(self.item)
text.setBrush(QBrush(QColor('#ddd')))
tw = text.boundingRect().width() / 2.
th = text.boundingRect().height() / 2.
x = -tw + center.x()
y = -th + center.y()
# Center text according to masterItem size
text.setPos(x, y)
示例6: ugly_name_face
# 需要导入模块: from PyQt4.QtGui import QGraphicsSimpleTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsSimpleTextItem import setParentItem [as 别名]
def ugly_name_face(node, *args, **kargs):
""" This is my item generator. It must receive a node object, and
returns a Qt4 graphics item that can be used as a node face.
"""
# receive an arbitrary number of arguments, in this case width and
# height of the faces
width = args[0][0]
height = args[0][1]
## Creates a main master Item that will contain all other elements
## Items can be standard QGraphicsItem
# masterItem = QGraphicsRectItem(0, 0, width, height)
# Or your custom Items, in which you can re-implement interactive
# functions, etc. Check QGraphicsItem doc for details.
masterItem = InteractiveItem(0, 0, width, height)
# Keep a link within the item to access node info
masterItem.node = node
# I dont want a border around the masterItem
masterItem.setPen(QPen(QtCore.Qt.NoPen))
# Add ellipse around text
ellipse = QGraphicsEllipseItem(masterItem.rect())
ellipse.setParentItem(masterItem)
# Change ellipse color
ellipse.setBrush(QBrush(QColor( random_color())))
# Add node name within the ellipse
text = QGraphicsSimpleTextItem(node.name)
text.setParentItem(ellipse)
text.setPen(QPen(QPen(QColor("white"))))
# Center text according to masterItem size
tw = text.boundingRect().width()
th = text.boundingRect().height()
center = masterItem.boundingRect().center()
text.setPos(center.x()-tw/2, center.y()-th/2)
return masterItem
示例7: iLabel
# 需要导入模块: from PyQt4.QtGui import QGraphicsSimpleTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsSimpleTextItem import setParentItem [as 别名]
def iLabel(node, *args, **kargs):
#code for making specialized faces for intermediates mostly cribbed from the ete2 website example (though not interactive):
# http://pythonhosted.org/ete2/tutorial/tutorial_drawing.html#creating-your-custom-interactive-item-faces
my_label = args[0][0] #or maybe just node.name?
ellipse = QGraphicsEllipseItem(0,0,fontSize*2,fontSize*2) #I think the first two are coords of center; second pair is major/minor axis
ellipse.setBrush(QBrush(QColor( 'black' )))
text = QGraphicsSimpleTextItem(my_label)
text.setParentItem(ellipse)
text.setBrush(QBrush(QColor("white")))
text.setFont(QFont("Arial",fontSize*.75))
#Center text according to masterItem size
tw = text.boundingRect().width()
th = text.boundingRect().height()
center = ellipse.boundingRect().center()
text.setPos(center.x()-tw/2, center.y()-th/2)
return ellipse
示例8: PathHelixHandle
# 需要导入模块: from PyQt4.QtGui import QGraphicsSimpleTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsSimpleTextItem import setParentItem [as 别名]
class PathHelixHandle(QGraphicsItem):
"""docstring for PathHelixHandle"""
radius = styles.PATHHELIXHANDLE_RADIUS
rect = QRectF(0, 0, 2*radius, 2*radius)
defBrush = QBrush(styles.grayfill)
defPen = QPen(styles.graystroke, styles.PATHHELIXHANDLE_STROKE_WIDTH)
hovBrush = QBrush(styles.bluefill)
hovPen = QPen(styles.bluestroke, styles.PATHHELIXHANDLE_STROKE_WIDTH)
useBrush = QBrush(styles.orangefill)
usePen = QPen(styles.orangestroke, styles.PATHHELIXHANDLE_STROKE_WIDTH)
def __init__(self, vhelix, parent):
super(PathHelixHandle, self).__init__(parent)
self.vhelix = vhelix
self.parent = parent
self.restoreParentItem = parent
self.setParentItem(parent)
self._number = self.vhelix.number()
self.label = None
self.focusRing = None
self.beingHoveredOver = False
self.setAcceptsHoverEvents(True)
self.font = QFont("Times", 30, QFont.Bold)
self.setNumber()
#self.setFlag(QGraphicsItem.ItemIsMovable)
self.setFlag(QGraphicsItem.ItemIsSelectable)
self.setFlag(QGraphicsItem.ItemSendsScenePositionChanges)
# end def
def boundingRect(self):
return self.rect
def paint(self, painter, option, widget=None):
if self._number >= 0:
if self.isSelected():
painter.setBrush(self.hovBrush)
painter.setPen(self.hovPen)
else:
painter.setBrush(self.useBrush)
painter.setPen(self.usePen)
else:
painter.setBrush(self.defBrush)
painter.setPen(self.defPen)
if self.beingHoveredOver:
painter.setPen(self.hovPen)
painter.drawEllipse(self.rect)
def setNumber(self):
"""docstring for setNumber"""
if self.label == None:
self.label = QGraphicsSimpleTextItem("%d" % self._number)
self.label.setFont(self.font)
self.label.setParentItem(self)
y_val = self.radius / 3
if self._number < 10:
self.label.setPos(self.radius / 1.5, y_val)
elif self._number < 100:
self.label.setPos(self.radius / 3, y_val)
else: # _number >= 100
self.label.setPos(0, y_val)
def number(self):
"""docstring for number"""
return self._number
class FocusRingPainter(QGraphicsItem):
"""Draws a focus ring around helix in parent"""
def __init__(self, helix, scene, parent=None):
super(PathHelixHandle.FocusRingPainter, self).__init__(parent)
self.parent = parent
self.scene = scene
self.helix = helix
self.setPos(helix.pos())
def paint(self, painter, option, widget=None):
painter.setPen(PathHelixHandle.hovPen)
painter.drawEllipse(self.helix.rect)
def boundingRect(self):
return self.helix.rect
# end class
def hoverEnterEvent(self, event):
"""
hoverEnterEvent changes the PathHelixHandle brush and pen from default
to the hover colors if necessary.
"""
if self.focusRing == None:
self.focusRing = PathHelixHandle.FocusRingPainter(self,\
self.scene(),\
self.parentItem())
self.update(self.rect)
# end def
def hoverLeaveEvent(self, event):
"""
hoverEnterEvent changes the PathHelixHanle brush and pen from hover
to the default colors if necessary.
#.........这里部分代码省略.........
示例9: write_header
# 需要导入模块: from PyQt4.QtGui import QGraphicsSimpleTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsSimpleTextItem import setParentItem [as 别名]
def write_header(self):
text = QGraphicsSimpleTextItem(self.header)
text.setFont(QFont("Arial", self.fsize))
text.setParentItem(self.item)
text.setPos(0, 5)