def shape(self): params = parameters.instance path = QPainterPath() scale = self.scale half_size = params.old_point_size / 2. path.moveTo(0, -half_size * scale[1]) path.lineTo(0, half_size * scale[1]) path.moveTo(-half_size * scale[0], 0) path.lineTo(half_size * scale[0], 0) return path
def __init_corner(self): path = QPainterPath() dpi = Info.dpi path.moveTo(-OIBlock.padding * 1.2 * dpi, (-.15 - OIBlock.padding * 1.2) * dpi) path.lineTo((-.15 - OIBlock.padding * 1.2) * dpi, -OIBlock.padding * 1.2 * dpi) path.lineTo(-OIBlock.padding * 1.2 * dpi, -OIBlock.padding * 1.2 * dpi) path.closeSubpath() self.__corner_path = path
def setShapeRect(self, rect): """ Set the item's shape `rect`. The item should be confined within this rect. """ path = QPainterPath() path.addEllipse(rect) self.setPath(path) self.__shapeRect = rect
def _paintPolygon(self, painter, polygon): path = QPainterPath() for line in polygon: ring = QPolygonF() for point in line: cur = self.toCanvasCoordinates(point) - self.pos() ring.append(cur) ring.append(ring[0]) path.addPolygon(ring) painter.drawPath(path)
def paint(self, painter, option, widget): params = parameters.instance pen = QPen(QColor(Qt.black)) scale = self.scale ms = min(scale) pen.setWidth(params.cell_thickness) sel_thick = 2 * params.cell_thickness if sel_thick == 0: sel_thick = 2 * ms col = None if self.current: col = QColor(params.selected_cell_color) elif self.hover: col = QColor(params.cell_hover_color) else: col = QColor(params.cell_color) painter.setBrush(col) if self.hover_contour: pen1 = QPen(QColor(Qt.white)) pen1.setWidth(sel_thick) painter.setPen(pen1) else: painter.setPen(pen) if isinstance(self.polygon, QPolygonF): painter.drawPolygon(self.polygon_shape) elif isinstance(self.polygon, QLineF): painter.drawLine(self.polygon) pen.setWidth(0) painter.setPen(pen) painter.drawPolygon(self.hexagon) if self.hover_side is not None: pen = QPen(QColor(Qt.red)) pen.setWidth(sel_thick) side = self.sides[self.hover_side] painter.setPen(pen) pp = QPainterPath() pp.moveTo(side[0]) for p in side[1:]: pp.lineTo(p) painter.drawPath(pp) elif self.division_line is not None: pen = QPen(params.division_wall_color) pen.setWidth(sel_thick) painter.setPen(pen) painter.drawLine(self.division_line) elif self.dragging_line: pen = QPen(QColor(Qt.red)) pen.setWidth(sel_thick) painter.setPen(pen) polygon = self.polygon dg = self.drag_side p1 = polygon[dg] p2 = polygon[dg + 1] painter.drawLine(p1, self.moving_point) painter.drawLine(self.moving_point, p2)
def paintEvent(self, event): painter = QPainter(self) btnRect = self.geometry() iconRect = self.iconSize() color = QColor(Qt.black) if self.hovered: color = self.color if self.pressed: color = self.color.darker(120) painter.setPen(QPen(QColor(Qt.lightGray), 2)) outline = QPainterPath() outline.addRoundedRect(0, 0, btnRect.width(), btnRect.height(), 0, 0) painter.setOpacity(1) painter.drawPath(outline) painter.setBrush(QBrush(color)) painter.setOpacity(self.opacity) painter_path = QPainterPath() painter_path.addRoundedRect(1, 1, btnRect.width() - 2, btnRect.height() - 2, 0, 0) if self.hovered: painter.setClipPath(painter_path) painter.drawRoundedRect(1, 1, btnRect.width() - 2, btnRect.height() - 2, 0, 0) painter.setOpacity(1) iconPos, textPos = self.calIconTextPos(btnRect, iconRect) # 重画文本 if not self.text().isNull(): painter.setFont(self.font()) painter.setPen(QPen(QColor(Qt.black), 2)) painter.drawText(textPos.x(), textPos.y(), textPos.width(), textPos.height(), Qt.AlignCenter, self.text()) # 重画图标 if not self.icon().isNull(): painter.drawPixmap(iconPos, QPixmap(self.icon().pixmap(self.iconSize())))
def paintEvent(self, QPaintEvent): p = QPainter(self.viewport()) clipPath = QPainterPath() clipPath.addEllipse(0, 0, 100, 100) p.setRenderHint(QPainter.Antialiasing) p.setClipPath(clipPath) p.setClipping(False) p.setPen(Qt.gray) p.drawPath(clipPath) self.update()
def chart(self, v1, v2): self.data1.pop(0) self.data2.pop(0) self.data1.append(v1) self.data2.append(v2) self.scene1 = QGraphicsScene() self.scene2 = QGraphicsScene() self.setup_scene(self.scene1) self.setup_scene(self.scene2) path = QPainterPath() path.moveTo(0, -self.data1[0] / 6) for i in xrange(1, 100): path.lineTo(2 * (i + 1), -self.data1[i] / 6) self.scene1.addPath(path, QPen(QColor(0, 0, 255), 3)) path = QPainterPath() path.moveTo(0, -self.data2[0] / 6) for i in xrange(1, 100): path.lineTo(2 * (i + 1), -self.data2[i] / 6) self.scene2.addPath(path, QPen(QColor(0, 0, 255), 3)) self.ui.chart1.setScene(self.scene1) self.ui.chart2.setScene(self.scene2)
def paint(self, painter, styleoptions, widget=None): try: width, realsize, label, fontsize = self._calc_size() except ZeroDivisionError: return mapunits = self.canvas.mapUnits() # painter.drawRect(self.boundingRect()) array = QPolygon() canvasheight = self.canvas.height() canvaswidth = self.canvas.width() margin = 20 originy = 0 originx = 0 self.setPos(margin, canvasheight - margin) x1, y1 = originx, originy x2, y2 = originx, originy + self.ticksize x3, y3 = originx + width, originy + self.ticksize midx, midy = originx + width / 2, originy + self.ticksize / 2 x4, y4 = originx + width, originy for pen in self.pens: painter.setPen(pen) # Drwa the scale bar painter.drawLine(x1, y1, x2, y2) painter.drawLine(x2, y2, x3, y3) painter.drawLine(x3, y3, x4, y4) painter.drawLine(midx, midy, midx, y1) # Draw the text fontwidth = self.metrics.width("0") fontheight = self.metrics.height() fontheight /= 2 fontwidth /= 2 path = QPainterPath() point = QPointF(x1 - fontwidth, y1 - fontheight) path.addText(point, self.font, "0") painter.setPen(self.whitepen) painter.setBrush(self.blackbrush) painter.setRenderHints(QPainter.Antialiasing) painter.setFont(self.font) painter.drawPath(path) fontwidth = self.metrics.width(label) fontheight = self.metrics.height() fontheight /= 2 fontwidth /= 2 point = QPointF(x4 - fontwidth, y4 - fontheight) path.addText(point, self.font, label) painter.drawPath(path)
def __updateCurve(self): self.prepareGeometryChange() if self.sourceAnchor and self.sinkAnchor: source_pos = self.sourceAnchor.anchorScenePos() sink_pos = self.sinkAnchor.anchorScenePos() source_pos = self.curveItem.mapFromScene(source_pos) sink_pos = self.curveItem.mapFromScene(sink_pos) # TODO: get the orthogonal angle to the anchors path. path = QPainterPath() path.moveTo(source_pos) path.cubicTo(source_pos + QPointF(60, 0), sink_pos - QPointF(60, 0), sink_pos) self.curveItem.setPath(path) self.sourceIndicator.setPos(source_pos) self.sinkIndicator.setPos(sink_pos) self.__updateText() else: self.setHoverState(False) self.curveItem.setPath(QPainterPath())
def test_layout(self): file_desc, disc_desc, bayes_desc = self.widget_desc() file_item = NodeItem() file_item.setWidgetDescription(file_desc) file_item.setPos(0, 150) self.scene.add_node_item(file_item) bayes_item = NodeItem() bayes_item.setWidgetDescription(bayes_desc) bayes_item.setPos(200, 0) self.scene.add_node_item(bayes_item) disc_item = NodeItem() disc_item.setWidgetDescription(disc_desc) disc_item.setPos(200, 300) self.scene.add_node_item(disc_item) link = LinkItem() link.setSourceItem(file_item) link.setSinkItem(disc_item) self.scene.add_link_item(link) link = LinkItem() link.setSourceItem(file_item) link.setSinkItem(bayes_item) self.scene.add_link_item(link) layout = AnchorLayout() self.scene.addItem(layout) self.scene.set_anchor_layout(layout) layout.invalidateNode(file_item) layout.activate() p1, p2 = file_item.outputAnchorItem.anchorPositions() self.assertGreater(p1, p2) self.scene.node_item_position_changed.connect(layout.invalidateNode) path = QPainterPath() path.addEllipse(125, 0, 50, 300) def advance(): t = time.clock() bayes_item.setPos(path.pointAtPercent(t % 1.0)) disc_item.setPos(path.pointAtPercent((t + 0.5) % 1.0)) self.singleShot(20, advance) advance() self.app.exec_()
def test_graphicspathobject(self): obj = GraphicsPathObject() path = QPainterPath() obj.setFlag(GraphicsPathObject.ItemIsMovable) path.addEllipse(20, 20, 50, 50) obj.setPath(path) self.assertEqual(obj.path(), path) self.assertTrue(obj.path() is not path, msg="setPath stores the path not a copy") brect = obj.boundingRect() self.assertTrue(area(brect) == 50**2) with self.assertRaises(TypeError): obj.setPath("This is not a path") brush = QBrush(QColor("#ffbb11")) obj.setBrush(brush) self.assertEqual(obj.brush(), brush) self.assertTrue(obj.brush() is not brush, "setBrush stores the brush not a copy") pen = QPen(QColor("#FFFFFF"), 1.4) obj.setPen(pen) self.assertEqual(obj.pen(), pen) self.assertTrue(obj.pen() is not pen, "setPen stores the pen not a copy") brect = obj.boundingRect() self.assertGreaterEqual(area(brect), (50 + 1.4 * 2)**2) self.assertIsInstance(obj.shape(), QPainterPath) positions = [] obj.positionChanged[QPointF].connect(positions.append) pos = QPointF(10, 10) obj.setPos(pos) self.assertEqual(positions, [pos]) self.scene.addItem(obj) self.view.show() self.app.exec_()
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
def paintMilestone(self, painter): """ Paints this item as the milestone look. :param painter | <QPainter> """ # generate the rect rect = self.rect() padding = self.padding() gantt = self.scene().ganttWidget() cell_w = gantt.cellWidth() cell_h = gantt.cellHeight() x = rect.width() - cell_w y = self.padding() w = cell_w h = rect.height() - padding - 2 # grab the color options color = self.color() alt_color = self.alternateColor() if (self.isSelected()): color = self.highlightColor() alt_color = self.alternateHighlightColor() # create the background brush gradient = QLinearGradient() gradient.setStart(0, 0) gradient.setFinalStop(0, h) gradient.setColorAt(0, color) gradient.setColorAt(0.8, alt_color) gradient.setColorAt(1, color) painter.setPen(self.borderColor()) painter.setBrush(QBrush(gradient)) pen = painter.pen() pen.setWidthF(0.5) painter.setPen(pen) painter.setRenderHint(painter.Antialiasing) path = QPainterPath() path.moveTo(x - cell_w / 3.0, y + h / 2.0) path.lineTo(x, y) path.lineTo(x + cell_w / 3.0, y + h / 2.0) path.lineTo(x, y + h) path.lineTo(x - cell_w / 3.0, y + h / 2.0) painter.drawPath(path)
def selectionShape(self): """ Return the current selection shape. This is the area selected/drawn by the user. Returns ------- shape : QPainterPath The selection shape in view coordinates. """ if self.__path is not None: shape = QPainterPath(self.__path) shape.closeSubpath() else: shape = QPainterPath() viewbox = self.viewBox() if viewbox is None: return QPainterPath() return viewbox.childGroup.mapFromParent(shape)
def drawGraph(self, plotter, change): pen = QPen(Qt.black, 2, Qt.SolidLine) plotter.setPen(pen) plotter.drawLine(20, 20, 20, 220) plotter.drawLine(20, 220, 220, 220) reactants = self._reaction.GetReactants() AverageReactantConc = 0 for x in range(self._reaction.REACTING_SPECIES_LIMIT): AverageReactantConc += reactants[x].GetInitialMoles() AverageReactantConc /= (len(reactants) * self._reaction.GetVolume()) plotter.setPen(QPen(plotter.GetReactantColour(), 2, Qt.SolidLine)) reactionpath = QPainterPath() reactionpath.moveTo(QPointF(20, 20)) reactionpath.arcTo(20, -70, 300 * change, 180, 180, 90) reactionpath.lineTo(220, 110) plotter.drawPath(reactionpath) plotter.setPen(QPen(plotter.GetProductColour(), 2, Qt.SolidLine)) productpath = QPainterPath() productpath.moveTo(QPointF(20, 220)) productpath.arcTo(20, 130, 300 * change, 180, 180, -90) productpath.lineTo(220, 130) plotter.drawPath(productpath)
def paintEvent(self, e): self._plotter.begin(self) if self._reaction.GetCatalyst().GetUsed(): change = self._reaction.GetCatalyst().GetEfficacy() else: change = 1 eqmpoint = 150 / change if change > 1: eqmpoint -= 0.1 * self._reaction.GetCatalyst().GetInitialMoles() elif change < 1: eqmpoint += 0.1 * self._reaction.GetCatalyst().GetInitialMoles() pen = QPen(Qt.black, 2, Qt.SolidLine) self._plotter.setPen(pen) self._plotter.drawLine(80, 20, 80, 220) self._plotter.drawLine(80, 220, 400, 220) self._plotter.setPen(QPen(self._reaction.GetReactantColour())) reactionpath = QPainterPath() reactionpath.moveTo(QPointF(80, 20)) reactionpath.arcTo(80, -80 + self._plotter.GetFinalY(), eqmpoint * 2, 200 - (2 * self._plotter.GetFinalY()), 180, 90) reactionpath.lineTo(400, 120 - self._plotter.GetFinalY()) self._plotter.drawPath(reactionpath) self._plotter.setPen(QPen(self._reaction.GetProductColour())) productpath = QPainterPath() productpath.moveTo(QPointF(80, 220)) productpath.arcTo(80, 120 + self._plotter.GetFinalY(), eqmpoint * 2, 200 - (2 * self._plotter.GetFinalY()), 180, -90) productpath.lineTo(400, 120 + self._plotter.GetFinalY()) self._plotter.drawPath(productpath) if not self._forprinting: white = QColor(240, 240, 240) self._plotter.setPen(QPen(white)) self._plotter.setBrush(white) self._plotter.drawRect(82 + self.parent().GetAnimUpdates() * 0.23, 20, 320, 198) self._plotter.setPen(QColor(0, 0, 0)) self._plotter.drawText(180, 235, "Time") self._plotter.drawText(0, 120, self._graphof) self._plotter.end()
def _test__2piece_simple(o, image_width, image_height): id1, id2 = 1, 2 from PyQt4.QtCore import QPointF from PyQt4.QtGui import QPainterPath path1 = QPainterPath() path1.moveTo(QPointF(0, 0)) path1.lineTo(QPointF(image_width * .3, 0)) path1.lineTo(QPointF(image_width * 0.7, image_height)) path1.lineTo(QPointF(0, image_height)) path1.lineTo(QPointF(0, 0)) o.make_piece_from_path(id1, path1) path2 = QPainterPath() path2.moveTo(QPointF(image_width, 0)) path2.lineTo(QPointF(image_width, image_height)) path2.lineTo(QPointF(image_width * 0.7, image_height)) path2.lineTo(QPointF(image_width * .3, 0)) path2.lineTo(QPointF(image_width, 0)) o.make_piece_from_path(id2, path2) o.add_relation(id1, id2)
def setPath(self, path): """Set the items `path` (:class:`QPainterPath`). """ if not isinstance(path, QPainterPath): raise TypeError("%r, 'QPainterPath' expected" % type(path)) if self.__path != path: self.prepareGeometryChange() # Need to store a copy of object so the shape can't be mutated # without properly updating the geometry. self.__path = QPainterPath(path) self.__boundingRect = None self.update()
def __init__( self, settings, x1, y1, x2, y2 ): QGraphicsPathItem.__init__( self ) self.__settings = settings path = QPainterPath() path.moveTo( x1, y1 ) path.lineTo( x2, y2 ) self.setPath( path ) self.penStyle = None self.penColor = None self.penWidth = None return
def _test_gridfunc(o, ge, image_width, image_height): id1, id2 = 1, 2 length_base = image_height # define raster points p1 = QPointF(0., 0.) p2 = QPointF(image_width / 2., 0.) p3 = QPointF(image_width, 0.) p4 = QPointF(0., image_height) p5 = QPointF(image_width / 2., image_height) p6 = QPointF(image_width, image_height) # generate edges middle_edge = ge.init_edge(QLineF(p2, p5), length_base) # piece1 p = QPainterPath() p.moveTo(p1) ge.add_plug_to_path( p, ge.init_edge(QLineF(p1, p2), length_base, is_straight=True)) ge.add_plug_to_path(p, middle_edge) ge.add_plug_to_path( p, ge.init_edge(QLineF(p5, p4), length_base, is_straight=True)) ge.add_plug_to_path( p, ge.init_edge(QLineF(p4, p1), length_base, is_straight=True)) ge.make_piece_from_path(id1, p) # piece2 p = QPainterPath() p.moveTo(p2) ge.add_plug_to_path( p, ge.init_edge(QLineF(p2, p3), length_base, is_straight=True)) ge.add_plug_to_path( p, ge.init_edge(QLineF(p3, p6), length_base, is_straight=True)) ge.add_plug_to_path( p, ge.init_edge(QLineF(p6, p5), length_base, is_straight=True)) ge.add_plug_to_path(p, middle_edge, reverse=True) ge.make_piece_from_path(id2, p) ge.add_relation(id1, id2)
def mouseMoveEvent(self, event): if event.buttons() & Qt.LeftButton: if self.__mode == PlotSelectionTool.Rect: rect = QRectF(event.buttonDownPos(Qt.LeftButton), event.pos()) self.__path = QPainterPath() self.__path.addRect(rect) else: self.__path.lineTo(event.pos()) self.selectionUpdated.emit(self.selectionShape()) self.__updategraphics() event.accept() return True else: return False
def arrow_path_plain(line, width): """ Return an :class:`QPainterPath` of a plain looking arrow. """ path = QPainterPath() p1, p2 = line.p1(), line.p2() if p1 == p2: return path baseline = QLineF(line) # Require some minimum length. baseline.setLength(max(line.length() - width * 3, width * 3)) path.moveTo(baseline.p1()) path.lineTo(baseline.p2()) stroker = QPainterPathStroker() stroker.setWidth(width) path = stroker.createStroke(path) arrow_head_len = width * 4 arrow_head_angle = 50 line_angle = line.angle() - 180 angle_1 = line_angle - arrow_head_angle / 2.0 angle_2 = line_angle + arrow_head_angle / 2.0 points = [ p2, p2 + QLineF.fromPolar(arrow_head_len, angle_1).p2(), p2 + QLineF.fromPolar(arrow_head_len, angle_2).p2(), p2 ] poly = QPolygonF(points) path_head = QPainterPath() path_head.addPolygon(poly) path = path.united(path_head) return path
def paint(self, painter, option, widget=None): myPen = self.pen() myPen.setColor(self.myColor) painter.setPen(myPen) painter.setBrush(self.myColor) controlPoints = [] endPt = self.endItem.getLinkPointForParameter(self.endIndex) startPt = self.startItem.getLinkPointForOutput(self.startIndex) if isinstance(self.startItem.element, Algorithm): if self.startIndex != -1: controlPoints.append(self.startItem.pos() + startPt) controlPoints.append(self.startItem.pos() + startPt + QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0)) controlPoints.append(self.endItem.pos() + endPt - QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0)) controlPoints.append(self.endItem.pos() + endPt) pt = QPointF(self.startItem.pos() + startPt + QPointF(-3, -3)) painter.drawEllipse(pt.x(), pt.y(), 6, 6) pt = QPointF(self.endItem.pos() + endPt + QPointF(-3, -3)) painter.drawEllipse(pt.x(), pt.y(), 6, 6) else: # Case where there is a dependency on an algorithm not # on an output controlPoints.append(self.startItem.pos() + startPt) controlPoints.append(self.startItem.pos() + startPt + QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0)) controlPoints.append(self.endItem.pos() + endPt - QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0)) controlPoints.append(self.endItem.pos() + endPt) else: controlPoints.append(self.startItem.pos()) controlPoints.append(self.startItem.pos() + QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0)) controlPoints.append(self.endItem.pos() + endPt - QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0)) controlPoints.append(self.endItem.pos() + endPt) pt = QPointF(self.endItem.pos() + endPt + QPointF(-3, -3)) painter.drawEllipse(pt.x(), pt.y(), 6, 6) path = QPainterPath() path.moveTo(controlPoints[0]) path.cubicTo(*controlPoints[1:]) painter.strokePath(path, painter.pen()) self.setPath(path)
def drawValue(self, p, baseRect, value, delta): if value == self.m_min: return dataPath = QPainterPath() dataPath.setFillRule(Qt.WindingFill) if value == self.m_max: dataPath.addEllipse(baseRect) else: arcLength = 360 / delta dataPath.moveTo(baseRect.center()) dataPath.arcTo(baseRect, self.m_nullPosition, -arcLength) dataPath.lineTo(baseRect.center()) p.setBrush(self.palette().highlight()) p.setPen(QPen(self.palette().shadow().color(), self.m_dataPenWidth)) p.drawPath(dataPath)
def updatePosition(self, scene): path = QPainterPath() self.prepareGeometryChange() count = len(self._longitudes) if count > 0: x, y = scene.posFromLonLat(self._longitudes, self._latitudes) dx = x - x[0] dy = y - y[0] for i in range(1, count): path.lineTo(dx[i], dy[i]) self.setPos(x[0], y[0]) self.setPath(path)
def venn_intersection(paths, key): if not any(key): return QPainterPath() # first take the intersection of all included paths path = reduce(QPainterPath.intersected, (path for path, included in zip(paths, key) if included)) # subtract all the excluded sets (i.e. take the intersection # with the excluded set complements) path = reduce(QPainterPath.subtracted, (path for path, included in zip(paths, key) if not included), path) return path
def ellipse_path(center, a, b, rotation=0): if not isinstance(center, QPointF): center = QPointF(*center) brect = QRectF(-a, -b, 2 * a, 2 * b) path = QPainterPath() path.addEllipse(brect) if rotation != 0: transform = QTransform().rotate(rotation) path = transform.map(path) path.translate(center) return path
def mouseReleaseEvent(self, event): QGraphicsView.mouseReleaseEvent(self, event) sc_pos = self.mapToScene(event.pos()) if self.zoomSelect: view_bb = self.sceneRect() if self.zoom_data: view_bb = self.zoom_data selection_bb = self.scene.selectionArea().boundingRect( ).intersected(view_bb) self.scene.setSelectionArea(QPainterPath()) if selection_bb.isValid() and (selection_bb != view_bb): self.zoom_data = selection_bb self.fitInView(self.zoom_data, Qt.KeepAspectRatio) self.setDragMode(QGraphicsView.NoDrag) self.afterLeftClickReleased.emit(sc_pos.x(), sc_pos.y())
def paintEvent(self, QPaintEvent): back = (numpy.ones((100, 200, 300)) * 0).astype(numpy.uint8) back[0:60, 0:60, 0:60] = 255 ol = (numpy.zeros((100, 200, 300))).astype(numpy.uint8) ol[0:99, 0:99, 0:99] = 120 ol[0:99, 120:140, 0:99] = 255 path = QPainterPath() path.addRect(20, 20, 60, 60) path.moveTo(0, 0) path.cubicTo(99, 0, 50, 50, 99, 99) path.cubicTo(0, 99, 50, 50, 0, 0) painter = QPainter(self) painter.fillRect(0, 0, 100, 100, Qt.Qt.red)