def update_style(self): self.setBackground(QBrush(QColor(CELL_BACKGROUND))) if self.style == u'numeric': self.setForeground(QBrush(QColor(CELL_NUMERIC_FOREGROUND))) self.setTextAlignment(Qt.AlignRight) elif self.style == u'text': self.setForeground(QBrush(QColor(CELL_TEXT_FOREGROUND))) self.setTextAlignment(Qt.AlignLeft) elif self.style == u'header': self.setTextAlignment(Qt.AlignCenter) self.set_header_style() else: raise Exception(u'Unknown style: %s' % self.style)
def set_resizable(self, resizing): # Update the resizer handle appearance and movability based on # the specified resizing state. if resizing: if self._debug: if self._anchor in ["B", "T", "R", "L"]: self.setBrush(QBrush(Qt.NoBrush)) else: self.setBrush(QBrush(Qt.green)) self.setPen(QPen(Qt.green)) self.setFlag(self.ItemIsMovable) else: self.setBrush(QBrush(Qt.NoBrush)) self.setPen(QPen(Qt.NoPen)) self.setFlag(self.ItemIsMovable, False)
def init_ui(self, history, blockcount): self.content_layout = QGridLayout(self) self.content_layout.setContentsMargins(0, 0, 0, 0) # self.content_layout.setSpacing(0) self.input_layout = QGridLayout() self.input_layout.setContentsMargins(0, 0, 0, 0) self.input_layout.setSpacing(0) # display for output self.out_display = ConsoleDisplay(blockcount) self.content_layout.addWidget(self.out_display, 1, 0, 1, 2) # colors to differentiate input, output and stderr self.inpfmt = self.out_display.currentCharFormat() self.inpfmt.setForeground( QBrush(QColor(self.window_theme.colors['primaryColor']))) self.outfmt = QTextCharFormat(self.inpfmt) self.outfmt.setForeground( QBrush(QColor(self.window_theme.colors['secondaryTextColor']))) self.errfmt = QTextCharFormat(self.inpfmt) self.errfmt.setForeground( QBrush(QColor(self.window_theme.colors['danger']))) # display input prompt left besides input edit self.prompt_label = QLabel('> ', self) self.prompt_label.setFixedWidth(15) self.input_layout.addWidget(self.prompt_label, 0, 0, 1, 1) self.prompt_label.hide() # command "text edit" for large code input self.inptextedit = ConsoleInputTextEdit(self.window_theme) self.input_layout.addWidget(self.inptextedit, 1, 0, 2, 2) self.inptextedit.hide() # command line self.inpedit = ConsoleInputLineEdit(self.inptextedit, max_history=history) self.inpedit.returned.connect(self.push) self.input_layout.addWidget(self.inpedit, 0, 1, 1, 1) self.content_layout.addLayout(self.input_layout, 2, 0, 1, 2) self.interp = None self.reset_interpreter() self.buffer = [] self.num_added_object_contexts = 0
def focusInEvent(self, event): self.setPen(QPen(highlight_color, 4)) self.arrow.setPen(QPen(highlight_color)) self.arrow.setBrush(QBrush(highlight_color)) self._arrow_height = 12 self.update_from_avoid_router() # trigger arrow size change super().focusInEvent(event)
def paintEvent(self, event): """ Override Qt method. Painting the scroll flag area """ make_flag = self.make_flag_qrect make_slider = self.make_slider_range # Filling the whole painting area painter = QPainter(self) painter.fillRect(event.rect(), self.editor.sideareas_color) block = self.editor.document().firstBlock() # Painting warnings and todos for line_number in range(1, self.editor.document().blockCount() + 1): data = block.userData() if data: position = self.value_to_position(line_number) if data.code_analysis: # Warnings color = self.editor.warning_color for _message, error in data.code_analysis: if error: color = self.editor.error_color break self.set_painter(painter, color) painter.drawRect(make_flag(position)) if data.todo: # TODOs self.set_painter(painter, self.editor.todo_color) painter.drawRect(make_flag(position)) if data.breakpoint: # Breakpoints self.set_painter(painter, self.editor.breakpoint_color) painter.drawRect(make_flag(position)) block = block.next() # Occurrences if self.editor.occurrences: self.set_painter(painter, self.editor.occurrence_color) for line_number in self.editor.occurrences: position = self.value_to_position(line_number) painter.drawRect(make_flag(position)) # Found results if self.editor.found_results: self.set_painter(painter, self.editor.found_results_color) for line_number in self.editor.found_results: position = self.value_to_position(line_number) painter.drawRect(make_flag(position)) # Painting the slider range pen_color = QColor(Qt.white) pen_color.setAlphaF(.8) painter.setPen(pen_color) brush_color = QColor(Qt.white) brush_color.setAlphaF(.5) painter.setBrush(QBrush(brush_color)) painter.drawRect( make_slider(self.editor.firstVisibleBlock().blockNumber()))
def draw_solution(self, func: str, args: Sequence[str], target: str, pos: Sequence[VPoint]) -> None: """Draw the solution triangle.""" points, color = self.solution_polygon(func, args, target, pos) color.setAlpha(150) pen = QPen(color) pen.setWidth(self.joint_size) self.painter.setPen(pen) def draw_arrow(index: int, text: str) -> None: """Draw arrow.""" x0, y0 = points[index] x1, y1 = points[-1] self.draw_arrow(x0, -y0, x1, -y1, zoom=False, line=False, text=text) draw_arrow(0, args[1]) if func == 'PLLP': draw_arrow(1, args[2]) color.setAlpha(30) self.painter.setBrush(QBrush(color)) self.painter.drawPolygon(QPolygonF([QPointF(x, y) for x, y in points])) self.painter.setBrush(Qt.NoBrush)
def __drawVertical(self, widget, option, painter, size, width): # drop between y_pos = option.rect.topLeft().y() if option.rect.height() == 0: # create indicators l_indicator = self.createTriangle(size, attrs.EAST) l_indicator.translate(QPoint(size + (width / 2), y_pos)) r_indicator = self.createTriangle(size, attrs.WEST) r_indicator.translate( QPoint(widget.width() - size - (width / 2), y_pos)) # draw painter.drawPolygon(l_indicator) painter.drawPolygon(r_indicator) painter.drawLine( QPoint(size + (width / 2), y_pos), QPoint(widget.width() - size - (width / 2), y_pos)) # set fill color background_color = QColor(*iColor["rgba_gray_1"]) brush = QBrush(background_color) path = QPainterPath() path.addPolygon(l_indicator) path.addPolygon(r_indicator) painter.fillPath(path, brush) # drop on else: indicator_rect = QRect((width / 2), y_pos, widget.width() - (width / 2), option.rect.height()) painter.drawRoundedRect(indicator_rect, 1, 1)
def get_cell_at(self, pos=None, mouse=False, highlight=False, sensitive=False): # Locate the the receptor grid cell at the specified parent # coordinates (if any) and return the associated row, column # index pair. If mouse is True, the cell currently under the # mouse cursor position is located instead of using pos. If # sensitive is True, the cell must be currently set to # sensitive in order to be considered. If highlight is True, # the specified cell is highlighted and the highlighting of # other cells is reset. r, c = None, None for ri, row in enumerate(self._cells): for ci, cell in enumerate(row): if mouse: cell_contains_pos = cell.isUnderMouse() else: cell_contains_pos = cell.contains(cell.mapFromParent(pos)) if (cell.isVisible() and cell_contains_pos and (cell.sensitive or not sensitive)): r, c = ri, ci if highlight: cell.setBrush(QBrush(Qt.green)) cell.setOpacity(0.5) else: return r, c else: if highlight: self._reset_appearance_of(cell) return r, c
def __init__(self, parent=None, circle=False): super(PyDMBitIndicator, self).__init__(parent) self.setAutoFillBackground(True) self.circle = circle self._painter = QPainter() self._brush = QBrush(Qt.SolidPattern) self._pen = QPen(Qt.SolidLine)
def __init__(self, anchor, parent=None): QGraphicsObject.__init__(self, parent=parent) MapItem.__init__(self) self.setZValue(200.0) anchorPos = self._posForAnchors[anchor] self._anchorPos = QPointF(anchorPos) self._anchor = anchor self._border = QGraphicsRectItem(parent=self) self._border.setPen(QPen(Qt.NoPen)) self._border.setBrush(QBrush(QColor(190, 190, 190, 160))) self._entries = list() imgfile = os.path.dirname(__file__) + os.sep + 'zoom_in_symbol.png' img = QPixmap(24, 24) img.load(imgfile) img = img.scaled(24, 24) img = ImageButton(img, parent=self) self.zoom_in_button = img self.addEntry(self.zoom_in_button) imgfile = os.path.dirname(__file__) + os.sep + 'zoom_out_symbol.png' img2 = QPixmap(24, 24) img2.load(imgfile) img2 = img2.scaled(24, 24) img2 = ImageButton(img2, parent=self) self.zoom_out_button = img2 self.addEntry(self.zoom_out_button)
def data_internal(self, index, record, role): result = None if role == Qt.DisplayRole: if index.column() == self.columnCount(INVALID_INDEX) - 1: result = record._cutelog else: column = self.table_header[index.column()] if column.name == 'asctime': result = record.asctime elif role == Qt.SizeHintRole: result = QSize(1, CONFIG.logger_row_height) elif role == Qt.FontRole: result = QFont(CONFIG.logger_table_font, CONFIG.logger_table_font_size) elif role == Qt.ForegroundRole: if not self.dark_theme: result = QColor(Qt.black) else: result = QColor(Qt.white) elif role == Qt.BackgroundRole: if not self.dark_theme: color = QColor(Qt.lightGray) else: color = QColor(Qt.darkGray) result = QBrush(color, Qt.BDiagPattern) return result
def __init__(self, *args): QMainWindow.__init__(self, *args) self.plot = QwtPlot(self) self.plot.setTitle("A Simple Map Demonstration") self.plot.setCanvasBackground(Qt.white) self.plot.setAxisTitle(QwtPlot.xBottom, "x") self.plot.setAxisTitle(QwtPlot.yLeft, "y") self.plot.setAxisScale(QwtPlot.xBottom, 0.0, 1.0) self.plot.setAxisScale(QwtPlot.yLeft, 0.0, 1.0) self.setCentralWidget(self.plot) # Initialize map data self.count = self.i = 1000 self.xs = np.zeros(self.count, np.float) self.ys = np.zeros(self.count, np.float) self.kappa = 0.2 self.curve = QwtPlotCurve("Map") self.curve.attach(self.plot) self.curve.setSymbol( QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.red), QPen(Qt.blue), QSize(5, 5)) ) self.curve.setPen(QPen(Qt.cyan)) toolBar = QToolBar(self) self.addToolBar(toolBar) # 1 tick = 1 ms, 10 ticks = 10 ms (Linux clock is 100 Hz) self.ticks = 10 self.tid = self.startTimer(self.ticks) self.timer_tic = None self.user_tic = None self.system_tic = None self.plot.replot()
def __init__(self, *, scene: QGraphicsScene, parent: QWidget = None): super().__init__(scene, parent) self.setRenderHints(QPainter.HighQualityAntialiasing) self.setTransformationAnchor(QGraphicsView.NoAnchor) self.setDragMode(QGraphicsView.ScrollHandDrag) self.setBackgroundBrush(QBrush(QColor(240, 240, 240), Qt.CrossPattern))
def paint(self, painter, option, index): QItemDelegate.paint(self, painter, option, index) column = index.column() row = index.row() rect = option.rect # Draw borders pen = QPen() pen.setWidth(1) pen.setColor(QColor('#cdcdcd')) painter.setPen(pen) painter.drawLine(rect.topLeft(), rect.topRight()) if (row == self.current_hover_row() or row == self.current_row() and (self.has_focus_or_context())): brush = QBrush(Qt.SolidPattern) brush.setColor(QColor(255, 255, 255, 100)) painter.fillRect(rect, brush) if row == self.current_row() and column in [const.COL_START]: pen = QPen() pen.setWidth(10) pen.setColor(QColor('#7cbb4c')) painter.setPen(pen) dyt = QPoint(0, 5) dyb = QPoint(0, 4) painter.drawLine(rect.bottomLeft()-dyb, rect.topLeft()+dyt)
def drawColorBar(self, painter, rect): h1, s1, v1, _ = self.__light.getHsv() h2, s2, v2, _ = self.__dark.getHsv() painter.save() painter.setClipRect(rect) painter.setClipping(True) painter.fillRect(rect, QBrush(self.__dark)) sectionSize = 2 if self.__orientation == Qt.Horizontal: numIntervals = rect.width() / sectionSize else: numIntervals = rect.height() / sectionSize section = QRect() for i in range(int(numIntervals)): if self.__orientation == Qt.Horizontal: section.setRect( rect.x() + i * sectionSize, rect.y(), sectionSize, rect.heigh() ) else: section.setRect( rect.x(), rect.y() + i * sectionSize, rect.width(), sectionSize ) ratio = float(i) / float(numIntervals) color = QColor() color.setHsv( h1 + int(ratio * (h2 - h1) + 0.5), s1 + int(ratio * (s2 - s1) + 0.5), v1 + int(ratio * (v2 - v1) + 0.5), ) painter.fillRect(section, color) painter.restore()
def __init__(self, parent=None, face_color=None, text_color=None): super().__init__(parent, text_color=text_color) self.face_color = face_color self.text_color = text_color self.plot_widget = pg.PlotWidget( self, axisItems={'bottom': pg.DateAxisItem()}, background=self.face_color) self.legend = self.plot_widget.addLegend( brush=QBrush(QColor(255, 255, 255)), offset=(-10, 10), labelTextColor=self.text_color, labelTextSize=8) self.v_layout.addWidget(self.plot_widget) # self.setMinimumSize(300, 200) # self.setMaximumSize(450, 300) self.xlabel: str = '' self.ylabel: str = '' self.threshold_range: TYPE_RANGE = None self.x_range: Tuple[float, float] = None self.y_range: Tuple[float, float] = None self.title: str = '' self.ticks = 5 self.show_data_num = 10 self.max_data = 200 self.timestamp_list = [] self.value_list = [] self.repaint_all = False
def draw_solution( self, func: str, args: Sequence[str], target: str, pos: Sequence[VPoint] ) -> None: """Draw the solution triangle.""" points, color = self.solution_polygon(func, args, target, pos) color.setAlpha(150) pen = QPen(color) pen.setWidth(self.joint_size) self.painter.setPen(pen) def draw_arrow(index: int, text: str) -> None: """Draw arrow.""" self.__draw_arrow( points[-1].x(), points[-1].y(), points[index].x(), points[index].y(), text=text ) draw_arrow(0, args[1]) if func == 'PLLP': draw_arrow(1, args[2]) color.setAlpha(30) self.painter.setBrush(QBrush(color)) self.painter.drawPolygon(QPolygonF(points)) self.painter.setBrush(Qt.NoBrush)
def drawGradient(self): """ Draws the gradient that will be displayed to the user """ _gradient = draw.drawColorTypeGradient(self.gradient_type, self.width(), self.height()) direction = self.linearCrosshairDirection() self.rgba_foreground.hide() # show gradient for RGBA gradient if self.gradient_type == attrs.RGBA: """ for some reason the darker it gets the harder of a time the picker has and the steps become larger and larger =/ """ # get value main_widget = getWidgetAncestor(self.views()[0], ColorGradientDelegate) value = main_widget.color().valueF() self.rgba_foreground.updateSize(QRectF(0, 0, self.width(), self.height())) self.rgba_foreground.updateGradient(value, self.width(), self.height()) self.rgba_foreground.show() # update linear gradient else: if direction == Qt.Horizontal: _gradient.setFinalStop(QPoint(self.width(), 0)) elif direction == Qt.Vertical: # TODO Move this to draw utils (gradient inversion) _gradient.setStart(QPoint(0, self.height())) _gradient.setFinalStop(QPoint(0, 0)) self.setBackgroundBrush(QBrush(_gradient))
def setBrush(self, brush): """ Assign a brush. In case of `brush.style() != QBrush.NoBrush` and `style() != QwtPlotCurve.Sticks` the area between the curve and the baseline will be filled. In case `not brush.color().isValid()` the area will be filled by `pen.color()`. The fill algorithm simply connects the first and the last curve point to the baseline. So the curve data has to be sorted (ascending or descending). :param brush: New brush :type brush: QBrush or QColor .. seealso:: :py:meth:`brush()`, :py:meth:`setBaseline()`, :py:meth:`baseline()` """ if isinstance(brush, QColor): brush = QBrush(brush) else: assert isinstance(brush, QBrush) if brush != self.__data.brush: self.__data.brush = brush self.legendChanged() self.itemChanged()
def paint(self, p, opt, widget): # Enforce constraints on handles r2 = Point(np.cos(np.radians(self.thetacenter)), np.sin(np.radians(self.thetacenter))) # chi center direction vector # constrain innerhandle to be parallel to outerhandle, and shorter than outerhandle self.innerhandle.setPos(r2 * self.innerradius) # constrain widthhandle to be counter-clockwise from innerhandle widthangle = np.radians(self.thetawidth / 2 + self.thetacenter) widthv = Point(np.cos(widthangle), np.sin(widthangle)) if self.thetawidth > 0 else r2 # constrain widthhandle to half way between inner and outerhandles self.widthhandle.setPos(widthv * (self.innerradius + self.outerradius) / 2) # constrain handles to base values self.outerhandle.setPos(r2 * self.outerradius) pen = self.currentPen pen.setColor(QColor(0, 255, 255)) p.setPen(pen) r = self.boundingRect() # p.drawRect(r) p.setRenderHint(QPainter.Antialiasing) p.scale(r.width(), r.height()) # workaround for GL bug centerangle = self.innerhandle.pos().angle(Point(1, 0)) startangle = centerangle - self.thetawidth / 2 endangle = centerangle + self.thetawidth / 2 r = QCircRectF(radius=0.5) if self.innerradius < self.outerradius and self.thetawidth > 0: p.drawArc(r, -startangle * 16, -self.thetawidth * 16) radius = self.innerradius / self.outerradius / 2 r = QCircRectF() r.radius = radius if self.innerradius < self.outerradius and self.thetawidth > 0: p.drawArc(r, -startangle * 16, -self.thetawidth * 16) pen.setStyle(Qt.DashLine) p.setPen(pen) p.drawLine(QPointF(0., 0.), self.widthhandle.pos().norm() / 2) r1v = self.innerhandle.pos().norm() p.drawLine(QPointF(0., 0.), (-1. * self.widthhandle.pos() + 2 * self.widthhandle.pos().dot(r1v) * r1v).norm() / 2) pen.setStyle(Qt.SolidLine) if self.innerradius < self.outerradius and self.thetawidth > 0: path = QPainterPath() path.moveTo((-1. * self.widthhandle.pos() + 2 * self.widthhandle.pos().dot(r1v) * r1v).norm() / 2) path.arcTo(r, -startangle, -self.thetawidth) # inside path.lineTo(self.widthhandle.pos().norm() / 2) # ? side path.arcTo(QCircRectF(radius=0.5), -endangle, self.thetawidth) # outside path.lineTo((-1. * self.widthhandle.pos() + 2 * self.widthhandle.pos().dot(r1v) * r1v).norm() / 2) self.path = path p.fillPath(path, QBrush(QColor(0, 255, 255, 20)))
def paint(self, painter, option, index): """ Overrides the selection highlight color. https://www.qtcentre.org/threads/41299-How-to-Change-QTreeView-highlight-color Note: this can actually do alot more than that with the QPalette... which is something I should learn how to use apparently... """ from qtpy.QtGui import QPalette item = index.internalPointer() new_option = QStyleOptionViewItem(option) brush = QBrush() if item.isEnabled(): color = QColor(*iColor["rgba_text"]) else: color = QColor(*iColor["rgba_text_disabled"]) # TODO highlight selection color??? # why did I move this here? brush.setColor(color) # brush2 = QBrush(QColor(0, 255, 0, 128)) new_option.palette.setBrush(QPalette.Normal, QPalette.HighlightedText, brush) # new_option.palette.setBrush(QPalette.Normal, QPalette.Highlight, brush2) QStyledItemDelegate.paint(self, painter, new_option, index) # if option.state == QStyle.State_Selected: # brush2 = QBrush(QColor(0, 255, 255, 128)) return
def __init__(self, parent=None, title=None): super(ErrorBarPlot, self).__init__("Errorbar Demonstation") self.setCanvasBackground(Qt.white) self.plotLayout().setAlignCanvasToScales(True) grid = QwtPlotGrid() grid.attach(self) grid.setPen(QPen(Qt.black, 0, Qt.DotLine)) # calculate data and errors for a curve with error bars x = np.arange(0, 10.1, 0.5, float) y = np.sin(x) dy = 0.2 * abs(y) # dy = (0.15 * abs(y), 0.25 * abs(y)) # uncomment for asymmetric error bars dx = 0.2 # all error bars the same size errorOnTop = False # uncomment to draw the curve on top of the error bars # errorOnTop = True # uncomment to draw the error bars on top of the curve symbol = QwtSymbol( QwtSymbol.Ellipse, QBrush(Qt.red), QPen(Qt.black, 2), QSize(9, 9) ) curve = ErrorBarPlotCurve( x=x, y=y, dx=dx, dy=dy, curvePen=QPen(Qt.black, 2), curveSymbol=symbol, errorPen=QPen(Qt.blue, 2), errorCap=10, errorOnTop=errorOnTop, ) curve.attach(self)
def __drawHorizontal(self, widget, option, painter, size, width): x_pos = option.rect.topLeft().x() if option.rect.width() == 0: # create indicators top_indicator = self.createTriangle(size, attrs.NORTH) top_indicator.translate(QPoint(x_pos, size + (width / 2))) bot_indicator = self.createTriangle(size, attrs.SOUTH) bot_indicator.translate( QPoint(x_pos, option.rect.height() - size - (width / 2))) # draw painter.drawPolygon(top_indicator) painter.drawPolygon(bot_indicator) painter.drawLine( QPoint(x_pos, size + (width / 2)), QPoint(x_pos, option.rect.height() - size + (width / 2))) # set fill color background_color = QColor(*iColor["rgba_gray_1"]) brush = QBrush(background_color) path = QPainterPath() path.addPolygon(top_indicator) path.addPolygon(bot_indicator) painter.fillPath(path, brush) # drop on else: painter.drawRoundedRect(option.rect, 1, 1)
def draw_icon(self, painter): path = QPainterPath(QPointF(0, 0.3)) path.lineTo(0, 0.9) path.lineTo(1, 0.3) path.lineTo(1, 0.9) path.closeSubpath() painter.drawPath(path) painter.drawLine(QPointF(0.5, 0.6), QPointF(0.5, 0.15)) # Draw the arrow end-caps painter.setBrush(QBrush(QColor(0, 0, 0))) top_arrow_point = QPointF(0.65, 0.36) arrow = QPolygonF([ QPointF(-0.09, 0.0), QPointF(-0.005, 0.0), QPointF(-0.005, 0.8), QPointF(0.005, 0.8), QPointF(0.005, 0.0), QPointF(0.09, 0.0), QPointF(0.00, -0.25) ]) t = QTransform() t.rotate(35) top_arrow_r = t.map(arrow) arrow_l = top_arrow_r.translated(top_arrow_point) painter.drawPolygon(arrow_l) painter.setBrush(self._interlock_brush) painter.drawRect(QRectF(0.3, 0, 0.4, 0.15))
def _fill_table(self, table_contents): self.table.setRowCount(len(table_contents)) for nr, row in enumerate(table_contents): for nc, entry in enumerate(row): s = textwrap.fill(entry, width=40) item = QTableWidgetItem(s) item.setFlags(item.flags() & ~Qt.ItemIsEditable) if not nc: item.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self.table.setItem(nr, nc, item) self.table.resizeRowsToContents() brightness = 220 for nr in range(self.table.rowCount()): for nc in range(self.table.columnCount()): self.table.item(nr, nc) if nr % 2: color = QColor(255, brightness, brightness) else: color = QColor(brightness, 255, brightness) self.table.item(nr, nc).setBackground(QBrush(color)) try: index = self._qe_param.index(self._qe_standard_selected) self.selected_standard_index = index n_columns = self.table.columnCount() self.table.setRangeSelected(QTableWidgetSelectionRange(index, 0, index, n_columns - 1), True) except ValueError: pass
def drawRoundFrame(self, painter, rect, palette, lineWidth, frameStyle): """ Draw a round frame :param QPainter painter: Painter :param QRectF rect: Target rectangle :param QPalette palette: `QPalette.WindowText` is used for plain borders, `QPalette.Dark` and `QPalette.Light` for raised or sunken borders :param int lineWidth: Line width :param int frameStyle: bitwise OR´ed value of `QFrame.Shape` and `QFrame.Shadow` """ Plain, Sunken, Raised = list(range(3)) style = Plain if (frameStyle & QFrame.Sunken) == QFrame.Sunken: style = Sunken elif (frameStyle & QFrame.Raised) == QFrame.Raised: style = Raised lw2 = 0.5 * lineWidth r = rect.adjusted(lw2, lw2, -lw2, -lw2) if style != Plain: c1 = palette.color(QPalette.Light) c2 = palette.color(QPalette.Dark) if style == Sunken: c1, c2 = c2, c1 gradient = QLinearGradient(r.topLeft(), r.bottomRight()) gradient.setColorAt(0.0, c1) gradient.setColorAt(1.0, c2) brush = QBrush(gradient) else: brush = palette.brush(QPalette.WindowText) painter.save() painter.setPen(QPen(brush, lineWidth)) painter.drawEllipse(r) painter.restore()
def __init__(self, parent=None): super(InteractiveVerticalLine, self).__init__(parent) self.setFlags( QGraphicsItem.ItemIsMovable | QGraphicsItem.ItemSendsGeometryChanges ) self.chartItemFlags = ChartItemFlags.FLAG_NO_AUTO_RANGE self.setZValue(1e6) self.setAcceptHoverEvents(True) self._x = None self._label = None self._pen = QPen(QBrush(Qt.green), 1.0, Qt.SolidLine) self._pen.setCosmetic(True) self._brush = QBrush(QColor(255, 255, 255, 0))
def paintEvent(self, event): """Override Qt method""" painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) # Decoration painter.fillPath(self.path_current, QBrush(self.color)) painter.strokePath(self.path_decoration, QPen(self.color_decoration, self.stroke_decoration))
def setX(self, x, label=None, color=QColor(Qt.red)): """ Sets the Vline's x value. :param x: abscissa value. :param label: :param color: """ self._x = x self.setPos(QPointF(self._x, 0)) if label is not None: self._label = label self._color = color self._pen = QPen(QBrush(color), 1.0, Qt.SolidLine) self._pen.setCosmetic(True) self._brush = QBrush(QColor(255, 255, 255, 0))
def setY(self, y, label=None, color=QColor(Qt.red)): """ Sets the Hline's y value :param y: Ordinate value :param label: :param color: """ self._y = y self.setPos(QPointF(0, self._y)) if label is not None: self._label = label self._color = color self._pen = QPen(QBrush(color), 1.0, Qt.SolidLine) self._pen.setCosmetic(True) self._brush = QBrush(QColor(255, 255, 255, 0))