本文整理汇总了Python中PyQt4.QtGui.QGraphicsPathItem.setPen方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsPathItem.setPen方法的具体用法?Python QGraphicsPathItem.setPen怎么用?Python QGraphicsPathItem.setPen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QGraphicsPathItem
的用法示例。
在下文中一共展示了QGraphicsPathItem.setPen方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FinishLine
# 需要导入模块: from PyQt4.QtGui import QGraphicsPathItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsPathItem import setPen [as 别名]
class FinishLine(QGraphicsItemGroup, AbstractSector):
def __init__(self, parent, pos, angle, pit=False):
QGraphicsItemGroup.__init__(self, parent)
AbstractSector.__init__(self, pos, angle)
self.setZValue(3)
self.black = QGraphicsPathItem(self)
self.white = QGraphicsPathItem(self)
start = 3 * (_trackWidth / 2)
end = -start - abs(_pitDistance if pit else 0)
rowdelta = _trackWidth / 4
for item, y in [(self.black, -rowdelta),
(self.white, rowdelta)]:
item.setCacheMode(QGraphicsPathItem.DeviceCoordinateCache)
self.addToGroup(item)
path = QPainterPath()
path.moveTo(start, y)
path.lineTo(end, y)
path.moveTo(end, -y)
path.lineTo(start, -y)
item.setPath(path)
pen = QPen(Qt.black, _trackWidth / 2)
pen.setCapStyle(Qt.FlatCap)
pen.setDashPattern([1, 1])
self.black.setPen(QPen(pen))
pen.setColor(Qt.white)
self.white.setPen(pen)
示例2: ParallelCoordinatesCurve
# 需要导入模块: from PyQt4.QtGui import QGraphicsPathItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsPathItem import setPen [as 别名]
class ParallelCoordinatesCurve(OWCurve):
def __init__(self, n_attributes, y_values, color, name=""):
OWCurve.__init__(self, tooltip=name)
self._item = QGraphicsPathItem(self)
self.path = QPainterPath()
self.fitted = False
self.n_attributes = n_attributes
self.n_rows = int(len(y_values) / n_attributes)
self.set_style(OWCurve.Lines)
if isinstance(color, tuple):
self.set_pen(QPen(QColor(*color)))
else:
self.set_pen(QPen(QColor(color)))
x_values = list(range(n_attributes)) * self.n_rows
self.set_data(x_values, y_values)
def update_properties(self):
self.redraw_path()
def redraw_path(self):
self.path = QPainterPath()
for segment in self.segment(self.data()):
if self.fitted:
self.draw_cubic_path(segment)
else:
self.draw_normal_path(segment)
self._item.setPath(self.graph_transform().map(self.path))
self._item.setPen(self.pen())
def segment(self, data):
for i in range(self.n_rows):
yield data[i * self.n_attributes:(i + 1) * self.n_attributes]
def draw_cubic_path(self, segment):
for (x1, y1), (x2, y2) in zip(segment, segment[1:]):
self.path.moveTo(x1, y1)
self.path.cubicTo(QPointF(x1 + 0.5, y1),
QPointF(x2 - 0.5, y2), QPointF(x2, y2))
def draw_normal_path(self, segment):
if not segment:
return
x, y = segment[0]
self.path.moveTo(x, y)
for x, y in segment[1:]:
self.path.lineTo(x, y)
示例3: _addPath
# 需要导入模块: from PyQt4.QtGui import QGraphicsPathItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsPathItem import setPen [as 别名]
def _addPath(self):
iNode = 2 * model._nodes.index(self.__node)
x0,y0 = record.states[0][iNode:iNode+2]
path = QPainterPath()
path.moveTo(x0,-y0)
item = QGraphicsPathItem()
item.setPen( QPen( QColor(0,0,255), 0 ) )
item.setPath(path)
self._path = item
for state in record.states[1:]:
self._addPoint(state)
if hasattr(record,'changeListeners'):
record.changeListeners.append(self._addPoint)
groupCurves.addToGroup(item)
示例4: ParallelCoordinatesCurve
# 需要导入模块: from PyQt4.QtGui import QGraphicsPathItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsPathItem import setPen [as 别名]
class ParallelCoordinatesCurve(OWCurve):
def __init__(self, attrCount, yData, color, name = ""):
OWCurve.__init__(self, tooltip=name)
self._item = QGraphicsPathItem(self)
self.fitted = False
self.set_style(OWCurve.Lines)
lineCount = len(yData) / attrCount
self.attrCount = attrCount
if type(color) == tuple:
self.set_pen(QPen(QColor(*color)))
else:
self.set_pen(QPen(QColor(color)))
self.set_data(range(attrCount) * lineCount, yData)
def update_properties(self):
if self.fitted:
path = self.cubicPath()
else:
path = QPainterPath()
for x, y in self.data():
path.lineTo(x, y)
self._item.setPath(self.graph_transform().map(path))
self._item.setPen(self.pen())
def cubicPath(self):
path = QPainterPath()
data = self.data()
for i in range(len(data) / self.attrCount):
segment = data[i*self.attrCount: (i + 1)*self.attrCount]
for i, p in enumerate(segment[:-1]):
x1, y1 = p
x2, y2 = segment[i + 1]
path.moveTo(x1, y1)
path.cubicTo(QPointF(x1 + 0.5, y1), QPointF(x2 - 0.5, y2), QPointF(x2, y2))
return path
示例5: PlotGrid
# 需要导入模块: from PyQt4.QtGui import QGraphicsPathItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsPathItem import setPen [as 别名]
class PlotGrid(orangeqt.PlotItem):
"""
Draws a grid onto the plot
:param plot: If specified, the grid will be attached to the ``plot``.
:type plot: :obj:`.OWPlot`
"""
def __init__(self, plot=None):
orangeqt.PlotItem.__init__(self)
self._x_enabled = True
self._y_enabled = True
self._path_item = QGraphicsPathItem(self)
self.set_in_background(True)
if plot:
self.attach(plot)
self._path_item.setPen(plot.color(OWPalette.Grid))
def set_x_enabled(self, b):
"""
Enables or disabled vertial grid lines
"""
if b < 0:
b = not self._x_enabled
self._x_enabled = b
self.update_properties()
def is_x_enabled(self):
"""
Returns whether vertical grid lines are enabled
"""
return self._x_enabled
def set_y_enabled(self, b):
"""
Enables or disabled horizontal grid lines
"""
if b < 0:
b = not self._y_enabled
self._y_enabled = b
self.update_properties()
def is_y_enabled(self):
"""
Returns whether horizontal grid lines are enabled
"""
return self._y_enabled
def set_pen(self, pen):
"""
Sets the pen used for drawing the grid lines
"""
self._path_item.setPen(pen)
def update_properties(self):
p = self.plot()
if p is None:
return
x_id, y_id = self.axes()
rect = p.data_rect_for_axes(x_id, y_id)
path = QPainterPath()
if self._x_enabled and x_id in p.axes:
for pos, label, size, _w in p.axes[x_id].ticks():
path.moveTo(pos, rect.bottom())
path.lineTo(pos, rect.top())
if self._y_enabled and y_id in p.axes:
for pos, label, size, _w in p.axes[y_id].ticks():
path.moveTo(rect.left(), pos)
path.lineTo(rect.right(), pos)
self._path_item.setPath(self.graph_transform().map(path))
示例6: TextAnnotation
# 需要导入模块: from PyQt4.QtGui import QGraphicsPathItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsPathItem import setPen [as 别名]
class TextAnnotation(Annotation):
"""Text annotation item for the canvas scheme.
"""
editingFinished = Signal()
"""Emitted when the editing is finished (i.e. the item loses focus)."""
textEdited = Signal()
"""Emitted when the edited text changes."""
def __init__(self, parent=None, **kwargs):
Annotation.__init__(self, parent, **kwargs)
self.setFlag(QGraphicsItem.ItemIsMovable)
self.setFlag(QGraphicsItem.ItemIsSelectable)
self.setFocusPolicy(Qt.ClickFocus)
self.__textMargins = (2, 2, 2, 2)
rect = self.geometry().translated(-self.pos())
self.__framePathItem = QGraphicsPathItem(self)
self.__framePathItem.setPen(QPen(Qt.NoPen))
self.__textItem = GraphicsTextEdit(self)
self.__textItem.setPlaceholderText(self.tr("Enter text here"))
self.__textItem.setPos(2, 2)
self.__textItem.setTextWidth(rect.width() - 4)
self.__textItem.setTabChangesFocus(True)
self.__textItem.setTextInteractionFlags(Qt.NoTextInteraction)
self.__textItem.setFont(self.font())
self.__textInteractionFlags = Qt.NoTextInteraction
layout = self.__textItem.document().documentLayout()
layout.documentSizeChanged.connect(self.__onDocumentSizeChanged)
self.__updateFrame()
def adjustSize(self):
"""Resize to a reasonable size.
"""
self.__textItem.setTextWidth(-1)
self.__textItem.adjustSize()
size = self.__textItem.boundingRect().size()
left, top, right, bottom = self.textMargins()
geom = QRectF(self.pos(), size + QSizeF(left + right, top + bottom))
self.setGeometry(geom)
def setFramePen(self, pen):
"""Set the frame pen. By default Qt.NoPen is used (i.e. the frame
is not shown).
"""
self.__framePathItem.setPen(pen)
def framePen(self):
"""Return the frame pen.
"""
return self.__framePathItem.pen()
def setFrameBrush(self, brush):
"""Set the frame brush.
"""
self.__framePathItem.setBrush(brush)
def frameBrush(self):
"""Return the frame brush.
"""
return self.__framePathItem.brush()
def setPlainText(self, text):
"""Set the annotation plain text.
"""
self.__textItem.setPlainText(text)
def toPlainText(self):
return self.__textItem.toPlainText()
def setHtml(self, text):
"""Set the annotation rich text.
"""
self.__textItem.setHtml(text)
def toHtml(self):
return self.__textItem.toHtml()
def setDefaultTextColor(self, color):
"""Set the default text color.
"""
self.__textItem.setDefaultTextColor(color)
def defaultTextColor(self):
return self.__textItem.defaultTextColor()
def setTextMargins(self, left, top, right, bottom):
"""Set the text margins.
"""
margins = (left, top, right, bottom)
if self.__textMargins != margins:
self.__textMargins = margins
self.__textItem.setPos(left, top)
#.........这里部分代码省略.........
示例7: __init__
# 需要导入模块: from PyQt4.QtGui import QGraphicsPathItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsPathItem import setPen [as 别名]
def __init__(self, world):
QGraphicsPolygonItem.__init__(self)
#############################
### Build graph
#############################
graph = pydot.Dot()
graph.set_node_defaults(color = 'red', fontcolor = 'red', label = '\<orphan\>')
graph.set('overlap', 'prism')
# build adjacency graph from world
for area in world.areas:
# create node for each room
node = pydot.Node(area.id)
node.set( 'label', area.name )
if area == world.player.currentArea:
node.set( 'color', 'blue' )
node.set( 'fontcolor', 'blue' )
else:
node.set( 'color', 'black' )
node.set( 'fontcolor', 'black' )
graph.add_node(node)
# link to adjacent rooms
for feature in area.features:
for action in feature.actions:
finalEvent = None
for event in action.events:
if type(event) == events.PlayerMoveEvent:
finalEvent = pydot.Edge( src=area.id, dst=event.properties['destination'] )
if finalEvent is not None:
graph.add_edge( finalEvent )
################################
### Generate SVG from graph
################################
ps = graph.create_svg(prog='neato')
#########################################
### Build graphics items from SVG
#########################################
# build xml tree
ns = {'svg': 'http://www.w3.org/2000/svg'}
doc = ET.fromstring(ps)
# grab the root node properties
rootNode = doc.xpath('/svg:svg/svg:g[1]', namespaces=ns)[0]
polygon = rootNode.xpath('./svg:polygon', namespaces=ns)[0]
pointStr = polygon.xpath('./@points', namespaces=ns)[0]
penColor = QString(polygon.xpath('./@stroke', namespaces=ns)[0])
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)
#.........这里部分代码省略.........
示例8: OWAxis
# 需要导入模块: from PyQt4.QtGui import QGraphicsPathItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsPathItem import setPen [as 别名]
class OWAxis(QGraphicsItem):
Role = OWPalette.Axis
def __init__(self, id, title = '', title_above = False, title_location = AxisMiddle, line = None, arrows = 0, plot = None):
QGraphicsItem.__init__(self)
self.setFlag(QGraphicsItem.ItemHasNoContents)
self.setZValue(AxisZValue)
self.id = id
self.title = title
self.title_location = title_location
self.data_line = line
self.plot = plot
self.graph_line = None
self.size = None
self.scale = None
self.tick_length = (10, 5, 0)
self.arrows = arrows
self.title_above = title_above
self.line_item = QGraphicsLineItem(self)
self.title_item = QGraphicsTextItem(self)
self.end_arrow_item = None
self.start_arrow_item = None
self.show_title = False
self.scale = None
path = QPainterPath()
path.setFillRule(Qt.WindingFill)
path.moveTo(0, 3.09)
path.lineTo(0, -3.09)
path.lineTo(9.51, 0)
path.closeSubpath()
self.arrow_path = path
self.label_items = []
self.label_bg_items = []
self.tick_items = []
self._ticks = []
self.zoom_transform = QTransform()
self.labels = None
self.auto_range = None
self.auto_scale = True
self.zoomable = False
self.update_callback = None
self.max_text_width = 50
self.text_margin = 5
self.always_horizontal_text = False
@staticmethod
def compute_scale(min, max):
magnitude = int(3*log10(abs(max-min)) + 1)
if magnitude % 3 == 0:
first_place = 1
elif magnitude % 3 == 1:
first_place = 2
else:
first_place = 5
magnitude = magnitude // 3 - 1
step = first_place * pow(10, magnitude)
first_val = ceil(min/step) * step
return first_val, step
def update_ticks(self):
self._ticks = []
major, medium, minor = self.tick_length
if self.labels is not None and not self.auto_scale:
for i, text in enumerate(self.labels):
self._ticks.append( ( i, text, medium, 1 ) )
else:
if self.scale and not self.auto_scale:
min, max, step = self.scale
elif self.auto_range:
min, max = self.auto_range
if min is not None and max is not None:
step = (max - min)/10
else:
return
else:
return
if max == min:
return
val, step = self.compute_scale(min, max)
while val <= max:
self._ticks.append( ( val, "%.4g" % val, medium, step ) )
val += step
def update_graph(self):
if self.update_callback:
self.update_callback()
def update(self, zoom_only = False):
self.update_ticks()
line_color = self.plot.color(OWPalette.Axis)
text_color = self.plot.color(OWPalette.Text)
if not self.graph_line or not self.scene():
return
self.line_item.setLine(self.graph_line)
self.line_item.setPen(line_color)
#.........这里部分代码省略.........
示例9: AxisScene
# 需要导入模块: from PyQt4.QtGui import QGraphicsPathItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsPathItem import setPen [as 别名]
class AxisScene(QGraphicsScene):
def __init__(self, parent = None):
super(AxisScene, self).__init__(parent)
self.guidePen = QPen(QColor("blue"),1)
self.dot = QGraphicsEllipseItem(-10, -10, 20, 20)
self.dot.setPos(QPointF(0,0))
self.dot.setPen(QPen(QColor("red"), 4))
self.dot.setBrush(QColor("black"))
self.lastPos = {}
self.lastPos['x'] = 0
self.lastPos['y'] = 0
self.grid = False
self.gridPen = QPen(QColor("blue"), 2)
self.pathItem = QGraphicsPathItem()
self.pathItem.setPen(QPen(QColor("red"), 1, Qt.DotLine))
self.path = None
self.xAxis = "Select Axis..."
self.yAxis = self.xAxis
self.addItem(self.dot)
def setXAxisName(self, x):
self.xAxis = "Axis " + str(x)
self.invalidate()
def setYAxisName(self, y):
self.yAxis = "Axis " + str(y)
self.invalidate()
def pathToggled(self, toggled):
if toggled:
self.path = QPainterPath()
self.path.moveTo(0,0)
self.pathItem.setPath(self.path)
self.addItem(self.pathItem)
else:
if self.path != None:
self.removeItem(self.pathItem)
self.path = None
self.invalidate()
def gridToggled(self, toggled):
self.grid = toggled
self.invalidate()
def updateDotX(self, x):
self.lastPos['x'] = x * (self.sceneRect().width() / 2)
self.update(self.lastPos['x'], self.lastPos['y'])
def updateDotY(self, y):
self.lastPos['y'] = y * (self.sceneRect().height() / 2)
self.update(self.lastPos['x'], self.lastPos['y'])
def update(self, x, y):
if self.path != None:
self.path.lineTo(x, y)
self.pathItem.setPath(self.path)
self.dot.setPos(self.lastPos['x'], self.lastPos['y'])
self.invalidate()
def drawBackground(self, painter, rect):
if self.grid:
painter.setClipRect(rect)
painter.setPen(self.gridPen)
def drawForeground(self, painter, rect):
painter.setClipRect(rect)
painter.setPen(self.gridPen)
r = self.sceneRect()
if self.grid:
painter.drawLine(r.center().x(), r.top(), r.center().x(), r.bottom())
painter.drawLine(r.left(), r.center().y(), r.right(), r.center().y())
painter.setPen(QPen(QColor("red"), 1))
painter.drawText(QRectF(r.left(), r.center().y(), 80, 80), self.xAxis)
painter.drawText(QRectF(r.center().x()+5, r.top(), 80, 80), self.yAxis)
if self.path != None:
painter.setPen(QPen(QColor("red"), 1))
painter.drawLine(QPointF(self.lastPos['x'], r.top()), QPointF(self.lastPos['x'], r.bottom()))
painter.drawLine(QPointF(r.left(), self.lastPos['y']), QPointF(r.right(), self.lastPos['y']))