def __init__(self, general_view, parent_item, points=None): super().__init__(parent_item) self.view = general_view self.view.viewport_rect_item.size_changed.connect( self.on_viewport_size_changed) self.point_items = [] self.pen = Qt.QPen(Qt.Qt.red) self.pen.setWidth(2) color = Qt.QColor(Qt.Qt.yellow) color.setAlphaF(0.5) self.brush = Qt.QBrush(color) self.brush_selected = Qt.QBrush(Qt.QColor(255, 0, 255, 127)) parent_item.installSceneEventFilter(self) if points: for point in points: self.make_and_store_point_item(Qt.QPointF(point[0], point[1]))
def checkSeries(self): if self.status: return self.status = 'checking' print("Checking...") for index, series in enumerate(seriesServices.getSeries()): results = seriesServices.checkOut(series['name']) brush = Qt.QBrush() if results: item = QtWidgets.QTableWidgetItem('OUT') brush.setColor(QColor(0, 255, 0)) box = QtWidgets.QComboBox() box.setEditable(True) box.setFixedWidth(100) for value in results: box.addItem(value) self.seriesTableWidget.setCellWidget(index, 4, box) else: item = QtWidgets.QTableWidgetItem('not out') brush.setColor(QColor(255, 0, 0)) item.setForeground(brush) self.seriesTableWidget.setItem(index, 3, item) QtWidgets.QApplication.processEvents() print('finished') self.status = ''
def __init__(self, *args): pg.PlotWidget.__init__(self, *args) # Set Global pyqtgraph options # Default foreground color for text, lines, axes, etc. pg.setConfigOption('foreground', 'k') # Default background for GraphicsView. pg.setConfigOption('background', None) # Draw lines with smooth edges at the cost of reduced performance. pg.setConfigOptions(antialias=True) self.ymax = 0 self.xmax = 0 self.ymin = 0 self.xmin = 0 self.setBackground(Qt.QBrush(Qt.Qt.darkCyan)) self.setRange(xRange=[-3, 3], yRange=[-2, 2]) axis = self.getAxis('bottom') axis.setStyle(tickLength=-10) axis.setPen(Qt.QPen(Qt.Qt.white, 1.025, Qt.Qt.DotLine)) axis = self.getAxis('left') axis.setStyle(tickLength=-10) axis.setPen(Qt.QPen(Qt.Qt.white, 1.025, Qt.Qt.DotLine)) self.plotItem.showGrid(x=True, y=True, alpha=100) self.drawUnitcircle()
def paintEvent(self, e): pix = qt.QPixmap(f'./static/avatar/{self.cover}.png') pix = pix.scaled(*self.size) painter = qt.QPainter(self) painter.setRenderHint(qt.QPainter.Antialiasing) painter.setBrush(qt.QBrush(pix)) painter.drawRoundedRect(0, 0, *self.size, self.round, self.round)
def paint(self, painter, option, midx): style = None if option.widget is not None: style = option.widget.style() if style is None: style = Qt.QApplication.style() # Fill cell background in the *exact same manner* as the default delegate. This is the simplest way to get the correct # cell background in all circumstances, including while dragging a row. style.drawPrimitive(Qt.QStyle.PE_PanelItemViewItem, option, painter, option.widget) d = midx.data(Qt.Qt.DecorationRole) if isinstance(d, Qt.QVariant): d = d.value() swatch_rect = Qt.QStyle.alignedRect(option.direction, Qt.Qt.AlignCenter, option.decorationSize, option.rect) painter.save() try: painter.setPen( Qt.QPen( option.palette.color(Qt.QPalette.Normal, Qt.QPalette.Mid))) painter.setBrush(Qt.QBrush(d)) painter.drawRect(swatch_rect) finally: painter.restore()
def painter_set_basic_painter(self): self.game_painter.setPen( qt.QPen(qt.QColor(0, 0, 0), 1, qtcore.Qt.SolidLine)) # self.game_painter.setBrush(qtcore.Qt.NoBrush) self.game_painter.setBrush( qt.QBrush(qt.QColor(254, 254, 254), qtcore.Qt.Dense4Pattern)) pass
def plot_polygon(rw, tck, width_tck, rgba): '''Plot the full polygon on RisWidget Parameters: ------------ rw: RisWidget Object Reference to the RisWidget object you want to display the spline on tck: parametric spline tuple Spline tuple of the centerline to plot width_tck: nonparametric spline tuple Spline tuple of the widths along the centerline to plot rgba: 3-d tuple of ints RGBA values to color the spline Returns: ----------- display_path: QGraphicsPathItem Reference to the display item displaying the spline ''' left, right, outline = spline_geometry.outline(tck, width_tck) #print(left) path = Qt.QPainterPath() path.moveTo(*outline[0]) for x, y in outline: path.lineTo(x, y) path.closeSubpath() display_path = Qt.QGraphicsPathItem(path, parent=rw.image_scene.layer_stack_item) pen = Qt.QBrush(Qt.QColor(*rgba, 90)) #pen.setColor(Qt.QColor(*rgba)) #pen.setWidth(1) #pen.setCosmetic(True) display_path.setBrush(pen) return display_path
def run(self): b = random.randrange(0, 500) rect = Qt.QRectF( random.randrange(0, 800) - b, random.randrange(0, 500) - b, b, b) color = Qt.Qt.yellow self.scene.addEllipse(rect, Qt.QPen(color), Qt.QBrush(color))
def __insertPole(self, color, px, py): curve = self.plot(name="Pole") curve.setPen(None) curve.setSymbol('x') curve.setSymbolPen('b') curve.setSymbolBrush(Qt.QBrush(Qt.Qt.gray)) curve.setSymbolSize(10) curve.setData(px, py)
def data(self, column, role): """Redefined from TreeItem.""" # pragma pylint: disable=redefined-variable-type res = super(HandleItem, self).data(column, role) if role in (Role.ReferenceRole,): res = self.is_reference elif role in (Q.Qt.BackgroundRole,): if self.itemData().is_repeated: return Q.QBrush(Q.QColor(Q.Qt.yellow)) else: return Q.QBrush(Q.QColor(Q.Qt.white)) elif column == FileData.file: if role in (Q.Qt.DisplayRole, Q.Qt.ToolTipRole, Role.SortRole): res = self._text(role != Q.Qt.ToolTipRole) elif role in (Q.Qt.UserRole,): return self.filename elif role in (Q.Qt.DecorationRole,): return get_icon("Unit") elif column == FileData.unit: if role in (Q.Qt.DisplayRole, Q.Qt.ToolTipRole,): res = '?' if self.unit is None else self.unit elif role in (Q.Qt.UserRole, Role.SortRole): res = self.unit elif column == FileData.inout: if role in (Q.Qt.DisplayRole, Q.Qt.ToolTipRole, Role.SortRole): res = FileAttr.value2str(self.attr) elif role in (Q.Qt.UserRole,): res = self.attr elif role in (Q.Qt.FontRole,): res = Q.QFont() res.setBold(self.is_forced_attr) elif column == FileData.exists: if role in (Q.Qt.DisplayRole, Q.Qt.ToolTipRole, Role.SortRole): res = bool2str(self.exists) elif role in (Q.Qt.UserRole,): res = self.exists elif column == FileData.embedded: if role in (Q.Qt.DisplayRole, Q.Qt.ToolTipRole, Role.SortRole): res = bool2str(self.embedded) elif role in (Q.Qt.UserRole,): res = self.embedded elif role in (Q.Qt.FontRole,): res = Q.QFont() res.setBold(self.is_forced_attr) return res
def __init__(self, o_color): self.m_pen = QtGui.QPen() #self.m_pen.setStyle(QtCore.Qt.NoPen) self.m_pen.setStyle(QtCore.Qt.SolidLine) self.m_pin_pen = Qt.QPen() #self.m_pen.setStyle(QtCore.Qt.NoPen) self.m_pin_pen.setStyle(QtCore.Qt.SolidLine) self.m_brush = Qt.QBrush() #self.m_brush.setStyle(QtCore.Qt.NoBrush) self.m_brush.setStyle(QtCore.Qt.SolidPattern) self.m_pin_brush = Qt.QBrush() #self.m_pin_brush.setStyle(QtCore.Qt.NoBrush) self.m_pin_brush.setStyle(QtCore.Qt.SolidPattern) self.set_color(o_color)
def __init__(self, general_view, parent_item, points=None): super().__init__(parent_item) self.view = general_view self.view.viewport_rect_item.size_changed.connect( self._on_viewport_size_changed) self.PointListType = self.POINT_LIST_TYPE self.pen = Qt.QPen(Qt.Qt.red) self.pen.setWidth(2) color = Qt.QColor(Qt.Qt.yellow) color.setAlphaF(0.5) self.brush = Qt.QBrush(color) self.brush_selected = Qt.QBrush(Qt.QColor(255, 0, 255, 127)) self._ignore_point_and_item_moved = False self._ignore_point_and_item_removed = False self.point_items = dict() self._points = None self.points = self.PointListType() if points is None else points self.parentItem().installSceneEventFilter(self)
def colorize_strings(self, strings, widget, cursorOffset=0): widget.clear() colors = (Qt.QBrush(Qt.QColor(QtCore.Qt.black)), Qt.QBrush(Qt.QColor(QtCore.Qt.blue)) ) cur = widget.textCursor() format = cur.charFormat() pos = cur.position() i = 0 for s in strings: format.setForeground(colors[i%2]) cur.insertText(s, format) if i == cursorOffset: pos = cur.position() i += 1 cur.setPosition(pos) widget.setTextCursor(cur) widget.centerCursor()
def data(self, midx, role=Qt.Qt.DisplayRole): if midx.isValid() and midx.column() == 0: image_list = self.signaling_list[midx.row()] if image_list is None: return Qt.QVariant() if role == Qt.Qt.ForegroundRole and len(image_list) == 0: return Qt.QApplication.palette().brush(Qt.QPalette.Disabled, Qt.QPalette.WindowText) elif role == Qt.Qt.BackgroundRole and image_list.color is not None: return Qt.QBrush(image_list.color) return super().data(midx, role)
def __init__(self, parent, layer_stack, brush, pen=None): super().__init__(*self.RECT, parent=parent) self.layer_stack = layer_stack view = self.scene().views()[0] self._zoom_changed(view.zoom) view.zoom_changed.connect(self._zoom_changed) if pen is None: pen = Qt.Qt.NoPen self.setPen(Qt.QPen(pen)) self.setBrush(Qt.QBrush(brush)) self.setFlag(Qt.QGraphicsItem.ItemIsMovable)
def pointAdd(self, scene: Qt.QGraphicsScene, xc: int, yc: int, col: int) -> Qt.QGraphicsScene: colour = Qt.QBrush() colour.setStyle(QtCore.Qt.SolidPattern) if col == 0: colour.setColor(Qt.QColor(255, 0, 0, 255)) elif col == 1: colour.setColor(Qt.QColor(0, 255, 0, 255)) else: colour.setColor(Qt.QColor(0, 0, 255, 255)) return scene.addEllipse(xc, yc, 23, 23, Qt.QPen(), colour)
def setCenter(self,x,y): if self.elipse: self.scene.removeItem(self.elipse) self.scene.removeItem(self.circle) self.elipse = self.scene.addEllipse(x-old_div(self.radius,2), y-old_div(self.radius,2), self.radius, self.radius, qt.QPen(QtCore.Qt.red, 1, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin), qt.QBrush(QtCore.Qt.red)) self.circle = self.scene.addEllipse(x-old_div(self.radius,2), y-old_div(self.radius,2), self.radius, self.radius, qt.QPen(QtCore.Qt.black, 1, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)) self.elipse.setVisible(False) self.circle.setVisible(True) self.scene.update()
def _show_dot_graph(self, dot, name): import io import pygraphviz gs = Qt.QGraphicsScene(self) gv = GV(gs) im = Qt.QImage.fromData( pygraphviz.AGraph(string=dot, directed=True).draw(format='png', prog='dot'), 'png') gs.addPixmap(Qt.QPixmap.fromImage(im)) gv.setDragMode(Qt.QGraphicsView.ScrollHandDrag) gv.setBackgroundBrush(Qt.QBrush(Qt.Qt.black)) gv.setWindowTitle(name) gv.show() return gv
def plot(self): self.scene = Qt.QGraphicsScene() self.graphics_view = Qt.QGraphicsView() self.graphics_view.setScene(self.scene) self.setCentralWidget(self.graphics_view) diameter = randint(0, 300) rect = Qt.QRectF(0, 0, diameter, diameter) colorlist = [ Qt.Qt.yellow, Qt.Qt.red, Qt.Qt.blue, Qt.Qt.green, Qt.Qt.black, Qt.Qt.gray, Qt.Qt.darkCyan ] color = colorlist[randint(0, 6)] self.scene.addEllipse(rect, Qt.QPen(color), Qt.QBrush(color))
def __init__(self, parent_item=None): super().__init__(parent_item) self._font = Qt.QFont('Courier', pointSize=16, weight=Qt.QFont.Bold) self._font.setKerning(False) self._font.setStyleHint(Qt.QFont.Monospace, Qt.QFont.OpenGLCompatible | Qt.QFont.PreferQuality) self._pen = Qt.QPen(Qt.QColor(Qt.Qt.black)) self._pen.setWidth(2) self._pen.setCosmetic(True) self._brush = Qt.QBrush(Qt.QColor(45,255,70,255)) self._text_flags = Qt.Qt.AlignLeft | Qt.Qt.AlignTop | Qt.Qt.AlignAbsolute self._picture = None self._bounding_rect = Qt.QRectF() # Necessary to prevent context information from disappearing when mouse pointer passes over # context info text self.setAcceptHoverEvents(False) self.setAcceptedMouseButtons(Qt.Qt.NoButton) self.hide()
def __init__(self, QwtPlot, chartHistoryLen, **kwargs): curveColor = kwargs.get('curveColor', Qt.Qt.green) curveTitle = kwargs.get('curveTitle', '') self.curveMovement = kwargs.get('curveMovement', 0) self.curve = Qwt.QwtPlotCurve(curveTitle) self.x = arange(0, chartHistoryLen, 1) self.y = zeros(len(self.x), Float) self.curve.attach(QwtPlot) self.curve.setPen(Qt.QPen(curveColor)) self.curve.setSymbol( Qwt.QwtSymbol( Qwt.QwtSymbol.Ellipse, Qt.QBrush(curveColor), Qt.QPen(curveColor), Qt.QSize(5, 5), ))
def on_update(self): if self.status: return self.status = 'updating' self.updatePushButton.setText('updating...') self.updatePushButton.setEnabled(False) Qt.QApplication.processEvents() for index, series in enumerate(seriesServices.getSeries()): result = seriesServices.getData(series['name']) brush = Qt.QBrush() if result: item = QtWidgets.QTableWidgetItem("updated") brush.setColor(QColor(0, 200, 0)) else: item = QtWidgets.QTableWidgetItem("update failed") brush.setColor(QColor(200, 0, 0)) item.setForeground(brush) self.seriesTableWidget.setItem(index, 3, item) self.updatePushButton.setText('&Update') self.updatePushButton.setEnabled(True) self.status = '' Qt.QApplication.processEvents()
def data(self, index=Qt.QModelIndex(), role=Qt.Qt.DisplayRole): if role == Qt.Qt.DisplayRole: if self.__decrypt_only_selected: selection = self.parent().selectionModel() if index in selection.selectedIndexes(): return self.__table[index.row()][index.column()].get_text( self.__random_password) else: return self.__table[index.row()][index.column()].get_text() else: return self.__table[index.row()][index.column()].get_text( self.__random_password) elif role == Qt.Qt.EditRole: return self.__table[index.row()][index.column()].get_text() elif role == Qt.Qt.BackgroundRole: if self.__table[index.row()][index.column()].is_encrypted(): return Qt.QBrush(Qt.QColor(250, 220, 220)) else: return Qt.QVariant() else: return Qt.QVariant()
from PyQt5 import QtCore, QtGui, QtWidgets, Qt from config import * font = QtGui.QFont("Georgia", 8) brush = Qt.QBrush(Qt.QColor(0xff, 0xff, 0xff)) class PanelLabel(QtWidgets.QWidget): """docstring for PanelLabel""" def __init__(self, parent, name): super(PanelLabel, self).__init__(parent) self.parent = parent # self.set_position(x, y) # Creates the scne self.scene = QtWidgets.QGraphicsScene() # Adds view into the scene self.view = QtWidgets.QGraphicsView(self.scene, self) self.view.setStyleSheet("border: 0px;") # Borderless background self.view.setHorizontalScrollBarPolicy( QtCore.Qt.ScrollBarAlwaysOff) # Without scroll bars self.view.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.view.setGeometry(0, 0, self.width(), self.height()) # Sets the geometry # For not shadowing it two times self.b_shadowed = False self.blink = False self.opacity = 255 self.max_opacity = 256 self.effect = QtWidgets.QGraphicsOpacityEffect(self) self.effect.setOpacity(self.opacity / self.max_opacity)
def painter_set_special_food_painter(self): self.game_painter.setPen( qt.QPen(qt.QColor(0, 0, 0), 1, qtcore.Qt.SolidLine)) self.game_painter.setBrush( qt.QBrush(qt.QColor(255, 0, 0), qtcore.Qt.Dense3Pattern))
def painter_set_food_painter(self): self.game_painter.setPen( qt.QPen(qt.QColor(0, 255, 0), 1, qtcore.Qt.SolidLine)) self.game_painter.setBrush( qt.QBrush(qt.QColor(0, 200, 0), qtcore.Qt.SolidPattern))
def paint(self, qpainter, option, widget): c = Qt.QColor(255, 0, 0, 128) qpainter.setPen(Qt.QPen(c)) qpainter.setBrush(Qt.QBrush(c)) qpainter.drawPath(self._path)
IDLE_COUNTER_WIDTH = 41 IDLE_COUNTER_HEIGHT = 14 SPACE_BETWEEN_COUNTER_AND_ICON = 6 IDLE_COUNTER_HEIGHT_WITH_SPACE = SPACE_BETWEEN_COUNTER_AND_ICON + IDLE_COUNTER_HEIGHT SPACE_BETWEEN_ICON_AND_BAR = 6 RESEARCH_BAR_WIDTH = 36 * 2 RESEARCH_BAR_HEIGHT = 20 # shouldnt be greater than ICON_SIZE_PX! RESEARCH_BAR_X = ICON_SIZE_PX + SPACE_BETWEEN_ICON_AND_BAR RESEARCH_BAR_Y = (ICON_SIZE_PX - RESEARCH_BAR_HEIGHT) // 2 # Centered # PyQT stuff WHITE_BRUSH = Qt.QBrush(Qt.QColor(0xff, 0xff, 0xff)) icon_top_text_font = QtGui.QFont("Georgia", 12) icon_top_text_font.setBold(True) icon_top_text_brush = WHITE_BRUSH icon_bottom_text_font = QtGui.QFont("Georgia", 12) icon_bottom_text_font.setBold(True) icon_bottom_text_brush = WHITE_BRUSH invisible_pen = Qt.QPen(Qt.QColor(0x00, 0x00, 0x00, 0x00)) invisible_pen.setWidth(0) alpha_brush = Qt.QBrush(Qt.QColor(0xff, 0xff, 0xff, 0x80))
def _update_picture(self): if self._picture is None: self._picture = Qt.QPicture() ppainter = Qt.QPainter() with ExitStack() as stack: ppainter.begin(self._picture) stack.callback(ppainter.end) # The Qt API calls required for formatting multiline text such that it can be rendered to # a path are private, as can be seen in the implementation of # QGraphicsSimpleTextItem::paint, pasted below. (Specifically, QStackTextEngine is a private # component and thus not available through PyQt). # # void QGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) # { # Q_UNUSED(widget); # Q_D(QGraphicsSimpleTextItem); # # painter->setFont(d->font); # # QString tmp = d->text; # tmp.replace(QLatin1Char('\n'), QChar::LineSeparator); # QStackTextEngine engine(tmp, d->font); # QTextLayout layout(&engine); # # QPen p; # p.setBrush(d->brush); # painter->setPen(p); # if (d->pen.style() == Qt::NoPen && d->brush.style() == Qt::SolidPattern) { # painter->setBrush(Qt::NoBrush); # } else { # QTextLayout::FormatRange range; # range.start = 0; # range.length = layout.text().length(); # range.format.setTextOutline(d->pen); # QList<QTextLayout::FormatRange> formats; # formats.append(range); # layout.setAdditionalFormats(formats); # } # # setupTextLayout(&layout); # layout.draw(painter, QPointF(0, 0)); # # if (option->state & (QStyle::State_Selected | QStyle::State_HasFocus)) # qt_graphicsItem_highlightSelected(this, painter, option); # } # # We would just use QGraphicsSimpleTextItem directly, but it is not derived from QGraphicsObject, so # it lacks the QObject base class required for emitting signals. It is not possible to add a QObject # base to a QGraphicsItem derivative in Python (it can be done in C++ - this is how QGraphicsObject # is implemented). # # Total lack of signal support is not acceptable; it would greatly complicate the task of # positioning a non-child item relative to a ContextualInfoItem. # # However, it's pretty easy to use that very paint function to generate paint commands that # we cache in self._picture, so we do that. For strings large enough that the relayout # performed on each refresh by QGraphicsSimpleTextItem exceeds the CPython interpreter overhead # for initiating the QPicture replay, our paint function is faster. # # Additionally, QGraphicsTextItem is very featureful, has a QObject base, and would be the first # choice, but the one thing it can not do is outline text, so it's out. i = Qt.QGraphicsSimpleTextItem(self.contextual_info.value) i.setFont(self._font) # Disabling brush/pen via setBrush/Pen(Qt.QBrush/Pen(Qt.Qt.NoBrush/Pen)) ought to be more intelligent # than disablind via setting to transparent color. However, using NoBrush or NoPen here seems to # cause extreme painting slowdowns on OS X. transparent_color = Qt.QColor(Qt.Qt.transparent) if self._pen is None or self._brush is None: i.setPen(Qt.QPen(transparent_color) if self._pen is None else self._pen) i.setBrush(Qt.QBrush(transparent_color) if self._brush is None else self._brush) i.paint(ppainter, Qt.QStyleOptionGraphicsItem(), None) else: # To ensure that character outlines never obscure the entirety of character interior, outline # is drawn first and interior second. If both brush and pen are nonempty, Qt draws interior first # and outline second. i.setBrush(Qt.QBrush(transparent_color)) i.setPen(self._pen) i.paint(ppainter, Qt.QStyleOptionGraphicsItem(), None) i.setBrush(self._brush) i.setPen(Qt.QPen(transparent_color)) i.paint(ppainter, Qt.QStyleOptionGraphicsItem(), None) self._bounding_rect = i.boundingRect()
def plot(self): rect = Qt.QRectF(0, 0, 90, 90) color = Qt.Qt.green self.scene.addEllipse(rect, Qt.QPen(color), Qt.QBrush(color))