本文整理汇总了Python中AnyQt.QtWidgets.QGraphicsLineItem类的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsLineItem类的具体用法?Python QGraphicsLineItem怎么用?Python QGraphicsLineItem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QGraphicsLineItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _draw_border
def _draw_border(point_1, point_2, border_width, parent):
pen = QPen(QColor(self.border_color))
pen.setCosmetic(True)
pen.setWidth(border_width)
line = QGraphicsLineItem(QLineF(point_1, point_2), parent)
line.setPen(pen)
return line
示例2: mouseMoveEvent
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)
示例3: create_main_nomogram
def create_main_nomogram(self, attributes, attr_inds, name_items, points,
max_width, point_text, name_offset):
cls_index = self.target_class_index
min_p = min(p.min() for p in points)
max_p = max(p.max() for p in points)
values = self.get_ruler_values(min_p, max_p, max_width)
min_p, max_p = min(values), max(values)
diff_ = np.nan_to_num(max_p - min_p)
scale_x = max_width / diff_ if diff_ else max_width
nomogram_header = NomogramItem()
point_item = RulerItem(point_text, values, scale_x, name_offset,
- scale_x * min_p)
point_item.setPreferredSize(point_item.preferredWidth(), 35)
nomogram_header.add_items([point_item])
self.nomogram_main = NomogramItem()
cont_feature_item_class = ContinuousFeature2DItem if \
self.cont_feature_dim_index else ContinuousFeatureItem
feature_items = [
DiscreteFeatureItem(
name_item, attr.values, point,
scale_x, name_offset, - scale_x * min_p)
if attr.is_discrete else
cont_feature_item_class(
name_item, self.log_reg_cont_data_extremes[i][cls_index],
self.get_ruler_values(
point.min(), point.max(),
scale_x * point.ptp(), False),
scale_x, name_offset, - scale_x * min_p)
for i, attr, name_item, point in zip(attr_inds, attributes, name_items, points)]
self.nomogram_main.add_items(feature_items)
self.feature_items = OrderedDict(sorted(zip(attr_inds, feature_items)))
x = - scale_x * min_p
y = self.nomogram_main.layout().preferredHeight() + 10
self.vertical_line = QGraphicsLineItem(x, -6, x, y)
self.vertical_line.setPen(QPen(Qt.DotLine))
self.vertical_line.setParentItem(point_item)
self.hidden_vertical_line = QGraphicsLineItem(x, -6, x, y)
pen = QPen(Qt.DashLine)
pen.setBrush(QColor(Qt.red))
self.hidden_vertical_line.setPen(pen)
self.hidden_vertical_line.setParentItem(point_item)
return point_item, nomogram_header
示例4: __init__
def __init__(self, parent=None):
QGraphicsLineItem.__init__(self, parent)
self.setAcceptHoverEvents(True)
self.__shape = None
self.__default_pen = QPen(QColor('#383838'), 4)
self.__default_pen.setCapStyle(Qt.RoundCap)
self.__hover_pen = QPen(QColor('#000000'), 4)
self.__hover_pen.setCapStyle(Qt.RoundCap)
self.setPen(self.__default_pen)
self.__shadow = QGraphicsDropShadowEffect(
blurRadius=10, color=QColor('#9CACB4'),
offset=QPointF(0, 0)
)
self.setGraphicsEffect(self.__shadow)
self.prepareGeometryChange()
self.__shadow.setEnabled(False)
示例5: test_controlpointline
def test_controlpointline(self):
control = ControlPointLine()
line = QGraphicsLineItem(10, 10, 200, 200)
self.scene.addItem(line)
self.scene.addItem(control)
control.setLine(line.line())
control.setFocus()
control.lineChanged.connect(line.setLine)
control.setLine(QLineF(30, 30, 180, 180))
self.assertEqual(control.line(), line.line())
self.assertEqual(line.line(), QLineF(30, 30, 180, 180))
control.lineEdited.connect(line.setLine)
self.view.show()
self.app.exec_()
self.assertEqual(control.line(), line.line())
示例6: addLink
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))
示例7: __init__
def __init__(self):
super().__init__(enableMenu=False)
self._profile_items = None
self._can_select = True
self._graph_state = SELECT
self.setMouseMode(self.PanMode)
pen = mkPen(LinePlotStyle.SELECTION_LINE_COLOR,
width=LinePlotStyle.SELECTION_LINE_WIDTH)
self.selection_line = QGraphicsLineItem()
self.selection_line.setPen(pen)
self.selection_line.setZValue(1e9)
self.addItem(self.selection_line, ignoreBounds=True)
示例8: __init__
def __init__(self, id, title='', title_above=False, title_location=AxisMiddle,
line=None, arrows=0, plot=None, bounds=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.values = None
self._bounds = bounds
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
示例9: __init__
def __init__(self, parent=None, line=QLineF(), text="", **kwargs):
super().__init__(parent, **kwargs)
self._text = text
self.setFlag(pg.GraphicsObject.ItemHasNoContents)
self._spine = QGraphicsLineItem(line, self)
angle = line.angle()
self._arrow = pg.ArrowItem(parent=self, angle=0)
self._arrow.setPos(self._spine.line().p2())
self._arrow.setRotation(angle)
self._arrow.setStyle(headLen=10)
self._label = TextItem(text=text, color=(10, 10, 10))
self._label.setParentItem(self)
self._label.setPos(*self.get_xy())
if parent is not None:
self.setParentItem(parent)
示例10: _offseted_line
def _offseted_line(ax, ay):
r = QGraphicsLineItem(x + ax, y + ay, x + (ax or w),
y + (ay or h))
self.canvas.addItem(r)
r.setPen(pen)
示例11: AnchorItem
class AnchorItem(pg.GraphicsObject):
def __init__(self, parent=None, line=QLineF(), text="", **kwargs):
super().__init__(parent, **kwargs)
self._text = text
self.setFlag(pg.GraphicsObject.ItemHasNoContents)
self._spine = QGraphicsLineItem(line, self)
angle = line.angle()
self._arrow = pg.ArrowItem(parent=self, angle=0)
self._arrow.setPos(self._spine.line().p2())
self._arrow.setRotation(angle)
self._arrow.setStyle(headLen=10)
self._label = TextItem(text=text, color=(10, 10, 10))
self._label.setParentItem(self)
self._label.setPos(*self.get_xy())
if parent is not None:
self.setParentItem(parent)
def get_xy(self):
point = self._spine.line().p2()
return point.x(), point.y()
def setText(self, text):
if text != self._text:
self._text = text
self._label.setText(text)
self._label.setVisible(bool(text))
def text(self):
return self._text
def setLine(self, *line):
line = QLineF(*line)
if line != self._spine.line():
self._spine.setLine(line)
self.__updateLayout()
def line(self):
return self._spine.line()
def setPen(self, pen):
self._spine.setPen(pen)
def setArrowVisible(self, visible):
self._arrow.setVisible(visible)
def paint(self, painter, option, widget):
pass
def boundingRect(self):
return QRectF()
def viewTransformChanged(self):
self.__updateLayout()
def __updateLayout(self):
T = self.sceneTransform()
if T is None:
T = QTransform()
# map the axis spine to scene coord. system.
viewbox_line = T.map(self._spine.line())
angle = viewbox_line.angle()
assert not np.isnan(angle)
# note in Qt the y axis is inverted (90 degree angle 'points' down)
left_quad = 270 < angle <= 360 or -0.0 <= angle < 90
# position the text label along the viewbox_line
label_pos = self._spine.line().pointAt(0.90)
if left_quad:
# Anchor the text under the axis spine
anchor = (0.5, -0.1)
else:
# Anchor the text over the axis spine
anchor = (0.5, 1.1)
self._label.setPos(label_pos)
self._label.setAnchor(pg.Point(*anchor))
self._label.setRotation(-angle if left_quad else 180 - angle)
self._arrow.setPos(self._spine.line().p2())
self._arrow.setRotation(180 - angle)
示例12: shape
def shape(self):
if self.__shape is None:
return QGraphicsLineItem.shape(self)
return self.__shape
示例13: hoverEnterEvent
def hoverEnterEvent(self, event):
self.prepareGeometryChange()
self.__shadow.setEnabled(True)
self.setPen(self.__hover_pen)
self.setZValue(1.0)
QGraphicsLineItem.hoverEnterEvent(self, event)
示例14: __init__
def __init__(self, name, data_extremes, values, scale, name_offset, offset):
super().__init__()
data_start, data_stop = data_extremes[0], data_extremes[1]
labels = [str(np.round(data_start + (data_stop - data_start) * i /
(self.n_tck - 1), 1)) for i in range(self.n_tck)]
# leading label
font = name.document().defaultFont()
name.setFont(font)
name.setPos(name_offset, -10)
name.setParentItem(self)
# labels
ascending = data_start < data_stop
y_start, y_stop = (self.y_diff, 0) if ascending else (0, self.y_diff)
for i in range(self.n_tck):
text = QGraphicsSimpleTextItem(labels[i], self)
w = text.boundingRect().width()
y = y_start + (y_stop - y_start) / (self.n_tck - 1) * i
text.setPos(-5 - w, y - 8)
tick = QGraphicsLineItem(-2, y, 2, y, self)
# prediction marker
self.dot = Continuous2DMovableDotItem(
self.DOT_RADIUS, scale, offset, values[0], values[-1], y_start, y_stop)
self.dot.tooltip_labels = labels
self.dot.tooltip_values = values
self.dot.setParentItem(self)
h_line = QGraphicsLineItem(values[0] * scale + offset, self.y_diff / 2,
values[-1] * scale + offset, self.y_diff / 2,
self)
pen = QPen(Qt.DashLine)
pen.setBrush(QColor(Qt.red))
h_line.setPen(pen)
self.dot.horizontal_line = h_line
# pylint: disable=unused-variable
# line
line = QGraphicsLineItem(values[0] * scale + offset, y_start,
values[-1] * scale + offset, y_stop,
self)
# ticks
for value in values:
diff_ = np.nan_to_num(values[-1] - values[0])
k = (value - values[0]) / diff_ if diff_ else 0
y_tick = (y_stop - y_start) * k + y_start - self.tick_height / 2
x_tick = value * scale - self.tick_width / 2 + offset
tick = QGraphicsRectItem(
x_tick, y_tick, self.tick_width, self.tick_height,
self)
tick.setBrush(QColor(Qt.black))
# rect
rect = QGraphicsRectItem(
values[0] * scale + offset, -self.y_diff * 0.125,
values[-1] * scale + offset, self.y_diff * 1.25,
self)
pen = QPen(Qt.DotLine)
pen.setBrush(QColor(50, 150, 200, 255))
rect.setPen(pen)
self.setPreferredSize(self.preferredWidth(), self.y_diff * 1.5)
示例15: hoverLeaveEvent
def hoverLeaveEvent(self, event):
self.prepareGeometryChange()
self.__shadow.setEnabled(False)
self.setPen(self.__default_pen)
self.setZValue(0.0)
QGraphicsLineItem.hoverLeaveEvent(self, event)