本文整理汇总了Python中AnyQt.QtWidgets.QGraphicsLineItem.setPen方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsLineItem.setPen方法的具体用法?Python QGraphicsLineItem.setPen怎么用?Python QGraphicsLineItem.setPen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QGraphicsLineItem
的用法示例。
在下文中一共展示了QGraphicsLineItem.setPen方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _draw_border
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsLineItem import setPen [as 别名]
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
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsLineItem import setPen [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)
示例3: addLink
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsLineItem import setPen [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: OWNomogram
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsLineItem import setPen [as 别名]
#.........这里部分代码省略.........
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
def get_ordered_attributes(self):
"""Return (in_domain_index, attr) pairs, ordered by method in SortBy combo"""
if self.domain is None or not self.domain.attributes:
return []
attrs = self.domain.attributes
sort_by = self.sort_index
class_value = self.target_class_index
if sort_by == SortBy.NO_SORTING:
return list(enumerate(attrs))
elif sort_by == SortBy.NAME:
def key(x):
_, attr = x
return attr.name.lower()
elif sort_by == SortBy.ABSOLUTE:
def key(x):
i, attr = x
if attr.is_discrete:
示例5: __init__
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsLineItem import setPen [as 别名]
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)
示例6: _offseted_line
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsLineItem import setPen [as 别名]
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)
示例7: AnchorItem
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsLineItem import setPen [as 别名]
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)
示例8: LinePlotViewBox
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsLineItem import setPen [as 别名]
class LinePlotViewBox(ViewBox):
selection_changed = Signal(np.ndarray)
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)
def update_selection_line(self, button_down_pos, current_pos):
p1 = self.childGroup.mapFromParent(button_down_pos)
p2 = self.childGroup.mapFromParent(current_pos)
self.selection_line.setLine(QLineF(p1, p2))
self.selection_line.resetTransform()
self.selection_line.show()
def set_graph_state(self, state):
self._graph_state = state
def enable_selection(self, enable):
self._can_select = enable
def get_selected(self, p1, p2):
if self._profile_items is None:
return np.array(False)
return line_intersects_profiles(np.array([p1.x(), p1.y()]),
np.array([p2.x(), p2.y()]),
self._profile_items)
def add_profiles(self, y):
if sp.issparse(y):
y = y.todense()
self._profile_items = np.array(
[np.vstack((np.full((1, y.shape[0]), i + 1), y[:, i].flatten())).T
for i in range(y.shape[1])])
def remove_profiles(self):
self._profile_items = None
def mouseDragEvent(self, event, axis=None):
if self._graph_state == SELECT and axis is None and self._can_select:
event.accept()
if event.button() == Qt.LeftButton:
self.update_selection_line(event.buttonDownPos(), event.pos())
if event.isFinish():
self.selection_line.hide()
p1 = self.childGroup.mapFromParent(
event.buttonDownPos(event.button()))
p2 = self.childGroup.mapFromParent(event.pos())
self.selection_changed.emit(self.get_selected(p1, p2))
elif self._graph_state == ZOOMING or self._graph_state == PANNING:
event.ignore()
super().mouseDragEvent(event, axis=axis)
else:
event.ignore()
def mouseClickEvent(self, event):
if event.button() == Qt.RightButton:
self.autoRange()
self.enableAutoRange()
else:
event.accept()
self.selection_changed.emit(np.array(False))
def reset(self):
self._profile_items = None
self._can_select = True
self._graph_state = SELECT
示例9: OWAxis
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsLineItem import setPen [as 别名]
#.........这里部分代码省略.........
for i, text in zip(values, 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)
if self.title:
self.title_item.setHtml('<b>' + self.title + '</b>')
self.title_item.setDefaultTextColor(text_color)
if self.title_location == AxisMiddle:
title_p = 0.5
elif self.title_location == AxisEnd:
title_p = 0.95
else:
title_p = 0.05
title_pos = self.graph_line.pointAt(title_p)
v = self.graph_line.normalVector().unitVector()
dense_text = False
if hasattr(self, 'title_margin'):
offset = self.title_margin
elif self._ticks:
if self.should_be_expanded():
offset = 55
dense_text = True
else:
offset = 35
else:
offset = 10
if self.title_above:
title_pos += (v.p2() - v.p1()) * (offset + QFontMetrics(self.title_item.font()).height())
else:
title_pos -= (v.p2() - v.p1()) * offset
## TODO: Move it according to self.label_pos
self.title_item.setVisible(self.show_title)
self.title_item.setRotation(-self.graph_line.angle())
c = self.title_item.mapToParent(self.title_item.boundingRect().center())