本文整理汇总了Python中PyQt4.QtGui.QGraphicsLineItem.setLine方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsLineItem.setLine方法的具体用法?Python QGraphicsLineItem.setLine怎么用?Python QGraphicsLineItem.setLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QGraphicsLineItem
的用法示例。
在下文中一共展示了QGraphicsLineItem.setLine方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mouseMoveEvent
# 需要导入模块: from PyQt4.QtGui import QGraphicsLineItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsLineItem import setLine [as 别名]
def mouseMoveEvent(self, event):
if event.buttons() & Qt.LeftButton:
downPos = event.buttonDownPos(Qt.LeftButton)
if not self.__tmpLine and self.__dragStartItem and \
(downPos - event.pos()).manhattanLength() > \
QApplication.instance().startDragDistance():
# Start a line drag
line = QGraphicsLineItem(self)
start = self.__dragStartItem.boundingRect().center()
start = self.mapFromItem(self.__dragStartItem, start)
line.setLine(start.x(), start.y(),
event.pos().x(), event.pos().y())
pen = QPen(Qt.black, 4)
pen.setCapStyle(Qt.RoundCap)
line.setPen(pen)
line.show()
self.__tmpLine = line
if self.__tmpLine:
# Update the temp line
line = self.__tmpLine.line()
line.setP2(event.pos())
self.__tmpLine.setLine(line)
QGraphicsWidget.mouseMoveEvent(self, event)
示例2: update
# 需要导入模块: from PyQt4.QtGui import QGraphicsLineItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsLineItem import setLine [as 别名]
def update(self):
x1 = self.node1.centerX()
y1 = self.node1.centerY()
x2 = self.node2.centerX()
y2 = self.node2.centerY()
point1 = QPointF(x1,y1)
point2 = QPointF(x2,y2)
line = QLineF(point1, point2)
QGraphicsLineItem.setLine(self,line)
示例3: addLink
# 需要导入模块: from PyQt4.QtGui import QGraphicsLineItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsLineItem import setLine [as 别名]
def addLink(self, output, input):
"""
Add a link between `output` (:class:`OutputSignal`) and `input`
(:class:`InputSignal`).
"""
if not compatible_channels(output, input):
return
if output not in self.source.output_channels():
raise ValueError("%r is not an output channel of %r" % \
(output, self.source))
if input not in self.sink.input_channels():
raise ValueError("%r is not an input channel of %r" % \
(input, self.sink))
if input.single:
# Remove existing link if it exists.
for s1, s2, _ in self.__links:
if s2 == input:
self.removeLink(s1, s2)
line = QGraphicsLineItem(self)
source_anchor = self.sourceNodeWidget.anchor(output)
sink_anchor = self.sinkNodeWidget.anchor(input)
source_pos = source_anchor.boundingRect().center()
source_pos = self.mapFromItem(source_anchor, source_pos)
sink_pos = sink_anchor.boundingRect().center()
sink_pos = self.mapFromItem(sink_anchor, sink_pos)
line.setLine(source_pos.x(), source_pos.y(),
sink_pos.x(), sink_pos.y())
pen = QPen(Qt.black, 4)
pen.setCapStyle(Qt.RoundCap)
line.setPen(pen)
self.__links.append(_Link(output, input, line))
示例4: OWAxis
# 需要导入模块: from PyQt4.QtGui import QGraphicsLineItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsLineItem import setLine [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)
#.........这里部分代码省略.........
示例5: EScene
# 需要导入模块: from PyQt4.QtGui import QGraphicsLineItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsLineItem import setLine [as 别名]
class EScene(QGraphicsScene):
def __init__(self, view=None, parent=None):
QGraphicsScene.__init__(self, parent)
if view is None:
raise AttributeError
self.__view = view
self.__create__()
def __create__(self):
self.__gridSize = 35
self.__isGridActive = True
self.__isAltModifier = False
self.__isControlModifier = False
self.__isNodePressed = False
self.__kDummy = EDummy()
self.__kDummy.setGridSize(self.__gridSize)
self.__kDummy.onPress.connect(self.__onNodePressed)
self.__kDummy.onEditEnd.connect(self.__onDummyEdit)
self.addItem(self.__kDummy)
self.__kSelected = ESceneSelection()
self.addItem(self.__kSelected)
self.__kCutLine = QGraphicsLineItem()
self.__kCutLine.hide()
self.addItem(self.__kCutLine)
self.__nodes = {}
self.__connections = {}
self.__graphHandle = EGraphHandle()
self.__graphHandle.Message.connect(self.__messageFilter)
self.__propEditor = EPropertyEditor()
self.addItem(self.__propEditor)
def __isNode(self, EObject):
return isinstance(EObject, ENode)
def __isEdge(self, EObject):
return isinstance(EObject, EEdge)
def __onNodePressed(self):
if self.__isNode(self.sender()):
self.__graphHandle.process(self.sender().mapFromPoint(self.__kDummy.scenePos()))
return
if not self.__kDummy.isEditMode():
self.__graphHandle.process(self.__kDummy.Id)
def __onDummyEdit(self, line):
if self.__isNode(self.itemAt(line.p1())) and self.__isNode(self.itemAt(line.p2())):
return
self.__kCutLine.setLine(line)
result = []
for item in self.__kCutLine.collidingItems():
if isinstance(item, EEdge):
if self.__kCutLine.collidesWithPath(item.shape()):
result.append(item.Id)
self.__graphHandle.process(result)
def __getDataFromId(self, theId):
handle = self.__graphHandle.getHandleFromId(theId)
if handle:
return self.__nodes[handle].mapFromId(theId)
return None
def __messageFilter(self, message):
if message.match(EGraphHandle.kMessageEditBegin):
self.__kDummy.toggleEditMode()
return
if message.match(EGraphHandle.kMessageEditEnd):
if self.__kDummy.isEditMode():
self.__kDummy.toggleEditMode()
return
if message.match(EGraphHandle.kMessageNodeAdded):
self.addItem(ENode(message.getData()))
return
if message.match(EGraphHandle.kMessageNodeRemoved):
#.........这里部分代码省略.........