本文整理汇总了Python中AnyQt.QtGui.QPen类的典型用法代码示例。如果您正苦于以下问题:Python QPen类的具体用法?Python QPen怎么用?Python QPen使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QPen类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, source, dest):
super().__init__()
self.setAcceptedMouseButtons(Qt.LeftButton)
self.setCacheMode(self.DeviceCoordinateCache) # Without this, burn thy CPU
self.setZValue(1)
pen = QPen(Edge.Color.DEFAULT[0], 1)
pen.setJoinStyle(Qt.MiterJoin)
self.setPen(pen)
self.arrowHead = QPolygonF()
self._selected = False
self._weights = []
self._labels = []
self.squares = GroupOfSquares(self)
self.source = source
self.dest = dest
if source is dest:
source.edges.append(self)
else:
source.edges.insert(0, self)
dest.edges.insert(0, self)
# Add text labels
label = self.label = TextItem('', self)
label.setFont(Edge.Font.DEFAULT)
label.setZValue(3)
self.adjust()
示例2: __init__
def __init__(self, tree_node, parent=None, **kwargs):
self.tree_node = tree_node
super().__init__(self._get_rect_attributes(), parent)
self.tree_node.graphics_item = self
self.setTransformOriginPoint(self.boundingRect().center())
self.setRotation(degrees(self.tree_node.square.angle))
self.setBrush(kwargs.get('brush', QColor('#297A1F')))
# The border should be invariant to scaling
pen = QPen(QColor(Qt.black))
pen.setWidthF(0.75)
pen.setCosmetic(True)
self.setPen(pen)
self.setAcceptHoverEvents(True)
self.setZValue(kwargs.get('zvalue', 0))
self.z_step = Z_STEP
# calculate the correct z values based on the parent
if self.tree_node.parent != TreeAdapter.ROOT_PARENT:
p = self.tree_node.parent
# override root z step
num_children = len(p.children)
own_index = [1 if c.label == self.tree_node.label else 0
for c in p.children].index(1)
self.z_step = int(p.graphics_item.z_step / num_children)
base_z = p.graphics_item.zValue()
self.setZValue(base_z + own_index * self.z_step)
示例3: _anchor_circle
def _anchor_circle(self):
# minimum visible anchor radius (radius)
minradius = self.radius / 100 + 1e-5
for item in chain(self.plotdata.anchoritem, self.plotdata.items):
self.viewbox.removeItem(item)
self.plotdata.anchoritem = []
self.plotdata.items = []
for anchor, var in zip(self.plotdata.anchors, self.data.domain.attributes):
if True or np.linalg.norm(anchor) > minradius:
axitem = AnchorItem(
line=QLineF(0, 0, *anchor), text=var.name,)
axitem.setVisible(np.linalg.norm(anchor) > minradius)
axitem.setPen(pg.mkPen((100, 100, 100)))
axitem.setArrowVisible(True)
self.plotdata.anchoritem.append(axitem)
self.viewbox.addItem(axitem)
hidecircle = QGraphicsEllipseItem()
hidecircle.setRect(
QRectF(-minradius, -minradius,
2 * minradius, 2 * minradius))
_pen = QPen(Qt.lightGray, 1)
_pen.setCosmetic(True)
hidecircle.setPen(_pen)
self.viewbox.addItem(hidecircle)
self.plotdata.items.append(hidecircle)
self.plotdata.hidecircle = hidecircle
示例4: _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
示例5: 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)
示例6: _anchor_circle
def _anchor_circle(self, variables):
# minimum visible anchor radius (radius)
min_radius = self._get_min_radius()
axisitems = []
for anchor, var in zip(self.plotdata.axes, variables[:]):
axitem = AnchorItem(line=QLineF(0, 0, *anchor), text=var.name,)
axitem.setVisible(np.linalg.norm(anchor) > min_radius)
axitem.setPen(pg.mkPen((100, 100, 100)))
axitem.setArrowVisible(True)
self.viewbox.addItem(axitem)
axisitems.append(axitem)
self.plotdata.axisitems = axisitems
if self.placement == self.Placement.Circular:
return
hidecircle = QGraphicsEllipseItem()
hidecircle.setRect(QRectF(-min_radius, -min_radius, 2 * min_radius, 2 * min_radius))
_pen = QPen(Qt.lightGray, 1)
_pen.setCosmetic(True)
hidecircle.setPen(_pen)
self.viewbox.addItem(hidecircle)
self.plotdata.hidecircle = hidecircle
示例7: LinkLineItem
class LinkLineItem(QGraphicsLineItem):
"""
A line connecting two Channel Anchors.
"""
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)
def setLine(self, *args, **kwargs):
super().setLine(*args, **kwargs)
# extends mouse hit area
stroke_path = QPainterPathStroker()
stroke_path.setCapStyle(Qt.RoundCap)
stroke_path.setWidth(10)
self.__shape = stroke_path.createStroke(super().shape())
def shape(self):
if self.__shape is None:
return QGraphicsLineItem.shape(self)
return self.__shape
def hoverEnterEvent(self, event):
self.prepareGeometryChange()
self.__shadow.setEnabled(True)
self.setPen(self.__hover_pen)
self.setZValue(1.0)
QGraphicsLineItem.hoverEnterEvent(self, event)
def hoverLeaveEvent(self, event):
self.prepareGeometryChange()
self.__shadow.setEnabled(False)
self.setPen(self.__default_pen)
self.setZValue(0.0)
QGraphicsLineItem.hoverLeaveEvent(self, event)
示例8: paint
def paint(self, painter, option, widget=None):
painter.save()
palette = self.palette()
border = palette.brush(QPalette.Mid)
pen = QPen(border, 1)
pen.setCosmetic(True)
painter.setPen(pen)
painter.setBrush(palette.brush(QPalette.Window))
brect = self.boundingRect()
painter.drawRoundedRect(brect, 4, 4)
painter.restore()
示例9: show_pearson
def show_pearson(rect, pearson, pen_width):
"""
Color the given rectangle according to its corresponding
standardized Pearson residual.
Args:
rect (QRect): the rectangle being drawn
pearson (float): signed standardized pearson residual
pen_width (int): pen width (bolder pen is used for selection)
"""
r = rect.rect()
x, y, w, h = r.x(), r.y(), r.width(), r.height()
if w == 0 or h == 0:
return
r = b = 255
if pearson > 0:
r = g = max(255 - 20 * pearson, 55)
elif pearson < 0:
b = g = max(255 + 20 * pearson, 55)
else:
r = g = b = 224
rect.setBrush(QBrush(QColor(r, g, b)))
pen_color = QColor(255 * (r == 255), 255 * (g == 255),
255 * (b == 255))
pen = QPen(pen_color, pen_width)
rect.setPen(pen)
if pearson > 0:
pearson = min(pearson, 10)
dist = 20 - 1.6 * pearson
else:
pearson = max(pearson, -10)
dist = 20 - 8 * pearson
pen.setWidth(1)
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)
ax = dist
while ax < w:
_offseted_line(ax, 0)
ax += dist
ay = dist
while ay < h:
_offseted_line(0, ay)
ay += dist
示例10: __updatePen
def __updatePen(self):
self.prepareGeometryChange()
self.__boundingRect = None
if self.__dynamic:
if self.__dynamicEnabled:
color = QColor(0, 150, 0, 150)
else:
color = QColor(150, 0, 0, 150)
normal = QPen(QBrush(color), 2.0)
hover = QPen(QBrush(color.darker(120)), 2.1)
else:
normal = QPen(QBrush(QColor("#9CACB4")), 2.0)
hover = QPen(QBrush(QColor("#7D7D7D")), 2.1)
if self.__state & LinkItem.Empty:
pen_style = Qt.DashLine
else:
pen_style = Qt.SolidLine
normal.setStyle(pen_style)
hover.setStyle(pen_style)
if self.hover:
pen = hover
else:
pen = normal
self.curveItem.setPen(pen)
示例11: _setup_plot
def _setup_plot(self):
target = self.target_index
selected = self.selected_classifiers
curves = [self.plot_curves(target, clf_idx) for clf_idx in selected]
for curve in curves:
self.plot.addItem(curve.curve_item)
if self.display_convex_hull:
hull = convex_hull([c.curve.hull for c in curves])
self.plot.plot(hull[0], hull[1], pen="y", antialias=True)
pen = QPen(QColor(100, 100, 100, 100), 1, Qt.DashLine)
pen.setCosmetic(True)
self.plot.plot([0, 1], [0, 1], pen=pen, antialias=True)
示例12: __init__
def __init__(self, size=None, offset=None, pen=None, brush=None):
super().__init__(size, offset)
self.layout.setContentsMargins(5, 5, 5, 5)
self.layout.setHorizontalSpacing(15)
self.layout.setColumnAlignment(1, Qt.AlignLeft | Qt.AlignVCenter)
if pen is None:
pen = QPen(QColor(196, 197, 193, 200), 1)
pen.setCosmetic(True)
self.__pen = pen
if brush is None:
brush = QBrush(QColor(232, 232, 232, 100))
self.__brush = brush
示例13: 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
示例14: crosshairs
def crosshairs(color, radius=24, circle=False):
radius = max(radius, 16)
pixmap = QPixmap(radius, radius)
pixmap.fill(Qt.transparent)
painter = QPainter()
painter.begin(pixmap)
painter.setRenderHints(QPainter.Antialiasing)
pen = QPen(QBrush(color), 1)
pen.setWidthF(1.5)
painter.setPen(pen)
if circle:
painter.drawEllipse(2, 2, radius - 2, radius - 2)
painter.drawLine(radius / 2, 7, radius / 2, radius / 2 - 7)
painter.drawLine(7, radius / 2, radius / 2 - 7, radius / 2)
painter.end()
return pixmap
示例15: paint
def paint(self, painter, option, widget=None):
# Override the default selected appearance
if self.isSelected():
option.state ^= QStyle.State_Selected
rect = self.rect()
# this must render before overlay due to order in which it's drawn
super().paint(painter, option, widget)
painter.save()
pen = QPen(QColor(Qt.black))
pen.setWidth(4)
pen.setJoinStyle(Qt.MiterJoin)
painter.setPen(pen)
painter.drawRect(rect.adjusted(2, 2, -2, -2))
painter.restore()
else:
super().paint(painter, option, widget)