本文整理汇总了Python中PyQt4.QtGui.QGraphicsEllipseItem.boundingRect方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsEllipseItem.boundingRect方法的具体用法?Python QGraphicsEllipseItem.boundingRect怎么用?Python QGraphicsEllipseItem.boundingRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QGraphicsEllipseItem
的用法示例。
在下文中一共展示了QGraphicsEllipseItem.boundingRect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: iLabel
# 需要导入模块: from PyQt4.QtGui import QGraphicsEllipseItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsEllipseItem import boundingRect [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
示例2: iLabel
# 需要导入模块: from PyQt4.QtGui import QGraphicsEllipseItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsEllipseItem import boundingRect [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
示例3: __init__
# 需要导入模块: from PyQt4.QtGui import QGraphicsEllipseItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsEllipseItem import boundingRect [as 别名]
#.........这里部分代码省略.........
fillColor = QString(polygon.xpath('./@fill', namespaces=ns)[0])
# parse root polygon path
path = QPolygonF()
for pair in pointStr.split(' '):
dims = pair.split(',')
point = QPointF( float(dims[0]), float(dims[1]) )
path.append(point)
self.setPolygon(path)
# fill in root node colors
if QColor.isValidColor(penColor):
self.setPen( QColor(penColor) )
if QColor.isValidColor(fillColor):
self.setBrush( QColor(fillColor) )
# build each graph node
for xmlNode in rootNode.xpath('./svg:g', namespaces=ns):
group = QGraphicsRectItem(self)
group.setPen( Qt.transparent )
group.setBrush( Qt.transparent )
if xmlNode.attrib['class'] == 'node':
# find the area object
name = xmlNode.xpath('./svg:title', namespaces=ns)[0].text
group.setData( 0, QString(world.areas[world.areaLookup[name]].id) )
# get the ellipse info
ellipseNode = xmlNode.xpath('./svg:ellipse', namespaces=ns)[0]
elProps = { k: float(ellipseNode.attrib[k]) for k in ['cx', 'cy', 'rx', 'ry']}
rect = QRectF( elProps['cx']-elProps['rx'], elProps['cy']-elProps['ry'], 2*elProps['rx'], 2*elProps['ry'])
penColor = QString(ellipseNode.attrib['stroke'])
ellipseItem = QGraphicsEllipseItem(rect, group)
if QColor.isValidColor(penColor):
ellipseItem.setPen( QColor(penColor) )
# get the text info
textNode = xmlNode.xpath('./svg:text', namespaces=ns)[0]
text = textNode.text
textItem = QGraphicsTextItem(text, group)
penColor = textNode.attrib.get('fill', 'black')
nodePoint = QPointF(float(textNode.attrib['x']), float(textNode.attrib['y']))
textItem.setPos( nodePoint - textItem.boundingRect().center() + QPointF(0.0,-4.0))
if QColor.isValidColor(penColor):
textItem.setDefaultTextColor( QColor(penColor) )
group.setRect( ellipseItem.boundingRect() )
group.setFlags( QGraphicsRectItem.ItemIsSelectable )
elif xmlNode.attrib['class'] == 'edge':
# parse the line portion of the arrow
line = xmlNode.xpath('./svg:path', namespaces=ns)[0]
path = QPainterPath()
# pull info from xml file
linePath = line.attrib['d']
lineColor = line.attrib['stroke']
# parse path coords
points = re.findall( '(-?\d+\.\d+),(-?\d+\.\d+)', linePath )
if len(points) != 4:
continue
startPoint = QPointF( float(points[0][0]), float(points[0][1]) )
path.moveTo(startPoint)
curvePoints = []
for pointCoord in points[1:]:
curvePoints.append( QPointF(float(pointCoord[0]), float(pointCoord[1])) )
path.cubicTo( curvePoints[0], curvePoints[1], curvePoints[2] )
# construct path item
pathItem = QGraphicsPathItem(path, group)
if QColor.isValidColor(lineColor):
pathItem.setPen( QColor(lineColor) )
polyNode = xmlNode.xpath('./svg:polygon', namespaces=ns)[0]
# pull info from xml file
pointStr = polyNode.xpath('./@points', namespaces=ns)[0]
penColor = QString(polyNode.xpath('./@stroke', namespaces=ns)[0])
fillColor = QString(polyNode.xpath('./@fill', namespaces=ns)[0])
# parse polygon path
path = QPolygonF()
for pair in pointStr.split(' '):
dims = pair.split(',')
point = QPointF( float(dims[0]), float(dims[1]) )
path.append(point)
# construct polygon item
polygonItem = QGraphicsPolygonItem(path, group)
if QColor.isValidColor(penColor):
polygonItem.setPen( QColor(penColor) )
if QColor.isValidColor(fillColor):
polygonItem.setBrush( QColor(fillColor) )
group.setRect( pathItem.boundingRect() and polygonItem.boundingRect() )