我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用PyQt5.QtCore.Qt.black()。
def draw_radar(self): """ Discards the current content and redraws all elements on the graphic scene. """ # decide which color to use bg_color, line_color = Qt.black, Qt.green self.scene.clear() self.scene.addRect(0, 0, self.width(), self.height(), brush=QBrush(bg_color)) self._add_crosshair() self._add_circles(self.circle_count, self.add_text_labels) # for each measurement, draw a line for measurement in self.measurements: assert isinstance(measurement, Measurement) added_time = self.added_time[measurement] self._add_measurement(measurement.distance, measurement.angle, added_time) # for the latest 2 measurements, draw an angle visualizer for measurement in self.measurements[-2:]: self._add_latest_input_line(measurement.angle)
def __init__(self): QtWidgets.QWidget.__init__(self) uic.loadUi("window.ui", self) self.scene = QGraphicsScene(0, 0, 711, 601) self.scene.win = self self.view.setScene(self.scene) self.image = QImage(710, 600, QImage.Format_Alpha8) self.image.fill(black) self.pen = QPen(black) self.draw.clicked.connect(lambda: draw(self)) self.dial_x.valueChanged.connect(lambda: draw(self)) self.dial_y.valueChanged.connect(lambda: draw(self)) self.dial_z.valueChanged.connect(lambda: draw(self)) self.funcs.addItem("cos(x) * sin(z)") self.funcs.addItem("2 * cos(x * z)") self.funcs.addItem("exp(sin(sqrt(x^2 + z^2)))") self.funcs.addItem("x^2 / 20 + z^2 / 20") self.funcs.addItem("|sin(x) * sin(z)|")
def __init__(self): QtWidgets.QWidget.__init__(self) uic.loadUi("window.ui", self) self.scene = Scene(0, 0, 561, 581) self.scene.win = self self.view.setScene(self.scene) self.image = QImage(561, 581, QImage.Format_ARGB32_Premultiplied) self.image.fill(Qt.white) self.bars.clicked.connect(lambda : set_bars(self)) self.erase.clicked.connect(lambda: clean_all(self)) self.paint.clicked.connect(lambda: clipping(self)) self.rect.clicked.connect(lambda: set_rect(self)) self.ect.clicked.connect(lambda: add_bars(self)) self.lock.clicked.connect(lambda: lock(self)) self.lines = [] self.edges = [] self.clip = None self.point_now_rect = None self.point_now_bars = None self.point_lock = None self.input_bars = False self.input_rect = False self.pen = QPen(black)
def __init__(self): QtWidgets.QWidget.__init__(self) uic.loadUi("window.ui", self) self.scene = Scene(0, 0, 561, 581) self.scene.win = self self.view.setScene(self.scene) self.poly.clicked.connect(lambda : set_pol(self)) self.erase.clicked.connect(lambda: clean_all(self)) self.paint.clicked.connect(lambda: clipping(self)) self.rect.clicked.connect(lambda: set_rect(self)) self.ect.clicked.connect(lambda: add_bars(self)) self.lock.clicked.connect(lambda: lock(self)) self.clip = [] self.pol = [] self.point_now_clip = None self.point_now_pol = None self.point_lock_pol = None self.point_lock_clip = None self.input_pol = False self.input_clip = False self.pen = QPen(black)
def __init__(self): QtWidgets.QWidget.__init__(self) uic.loadUi("window.ui", self) self.scene = QtWidgets.QGraphicsScene(0, 0, 511, 511) self.mainview.setScene(self.scene) self.image = QImage(511, 511, QImage.Format_ARGB32_Premultiplied) self.pen = QPen() self.color_line = QColor(Qt.black) self.color_bground = QColor(Qt.white) self.draw_once.clicked.connect(lambda: draw_once(self)) self.clean_all.clicked.connect(lambda: clear_all(self)) self.btn_bground.clicked.connect(lambda: get_color_bground(self)) self.btn_line.clicked.connect(lambda: get_color_line(self)) self.draw_centr.clicked.connect(lambda: draw_centr(self)) layout = QtWidgets.QHBoxLayout() layout.addWidget(self.what) layout.addWidget(self.other) self.setLayout(layout) self.circle.setChecked(True) self.canon.setChecked(True) #self.circle.toggled.connect(lambda : change_text(self))
def __init__(self): super(VideoStyleDark, self).__init__() palette = qApp.palette() palette.setColor(QPalette.Window, QColor(27, 35, 38)) palette.setColor(QPalette.WindowText, QColor(234, 234, 234)) palette.setColor(QPalette.Base, QColor(27, 35, 38)) palette.setColor(QPalette.AlternateBase, QColor(12, 15, 16)) palette.setColor(QPalette.ToolTipBase, QColor(27, 35, 38)) palette.setColor(QPalette.ToolTipText, Qt.white) palette.setColor(QPalette.Text, QColor(234, 234, 234)) palette.setColor(QPalette.Button, QColor(27, 35, 38)) palette.setColor(QPalette.ButtonText, Qt.white) palette.setColor(QPalette.BrightText, QColor(100, 215, 222)) palette.setColor(QPalette.Link, QColor(126, 71, 130)) palette.setColor(QPalette.Highlight, QColor(126, 71, 130)) palette.setColor(QPalette.HighlightedText, Qt.white) palette.setColor(QPalette.Disabled, QPalette.Light, Qt.black) palette.setColor(QPalette.Disabled, QPalette.Shadow, QColor(12, 15, 16)) qApp.setPalette(palette)
def drawCellGlyph(self, painter): if self.shouldDrawLayers: layers = self.font.layers for layerName in reversed(layers.layerOrder): layer = layers[layerName] if self.glyph.name not in layer: continue layerColor = None if layer.color is not None: layerColor = colorToQColor(layer.color) if layerColor is None: layerColor = Qt.black glyph = layer[self.glyph.name] path = glyph.getRepresentation("defconQt.QPainterPath") painter.fillPath(path, layerColor) else: path = self.glyph.getRepresentation("defconQt.QPainterPath") painter.fillPath(path, Qt.black)
def data(self, role): if role in (Qt.EditRole, Qt.StatusTipRole): return self.formula() if role == Qt.DisplayRole: return self.display() t = str(self.display()) try: number = int(t) except ValueError: number = None if role == Qt.TextColorRole: if number is None: return QColor(Qt.black) elif number < 0: return QColor(Qt.red) return QColor(Qt.blue) if role == Qt.TextAlignmentRole: if t and (t[0].isdigit() or t[0] == '-'): return Qt.AlignRight | Qt.AlignVCenter return super(SpreadSheetItem, self).data(role)
def updateLockStatus(self, status, reason): indicationColor = Qt.black if status == QCamera.Searching: self.ui.statusbar.showMessage("Focusing...") self.ui.lockButton.setText("Focusing...") indicationColor = Qt.yellow elif status == QCamera.Locked: self.ui.lockButton.setText("Unlock") self.ui.statusbar.showMessage("Focused", 2000) indicationColor = Qt.darkGreen elif status == QCamera.Unlocked: self.ui.lockButton.setText("Focus") if reason == QCamera.LockFailed: self.ui.statusbar.showMessage("Focus Failed", 2000) indicationColor = Qt.red palette = self.ui.lockButton.palette() palette.setColor(QPalette.ButtonText, indicationColor) self.ui.lockButton.setPalette(palette)
def paintGL(self): GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glPushMatrix() GL.glEnable(GLWidget.GL_MULTISAMPLE) GL.glTranslatef( -0.25, -0.10, 0.0) GL.glScalef(0.75, 1.15, 0.0) GL.glRotatef(GLWidget.rot, 0.0, 0.0, 1.0) GL.glCallList(self.list_) GL.glPopMatrix() GL.glPushMatrix() GL.glDisable(GLWidget.GL_MULTISAMPLE) GL.glTranslatef(0.25, -0.10, 0.0) GL.glScalef(0.75, 1.15, 0.0) GL.glRotatef(GLWidget.rot, 0.0, 0.0, 1.0) GL.glCallList(self.list_) GL.glPopMatrix() GLWidget.rot += 0.2 self.qglColor(Qt.black) self.renderText(-0.35, 0.4, 0.0, "Multisampling enabled") self.renderText(0.15, 0.4, 0.0, "Multisampling disabled")
def initUI(self): # QToolTip.setFont(QFont('SansSerif', 9)) self.cwidget = GUICenterWidget() self.setCentralWidget(self.cwidget) # self.setToolTip('This is a <b>QWidget</b> widget') self.statusBar().showMessage('Ready') self.center() self.setWindowTitle('Coliform Control GUI') self.onewiretimer = QTimer(self) self.onewiretimer.timeout.connect(self.cwidget.onewireOn) self.onewiretimer.start(1000) # self.p = QPalette(self.palette()) # self.p.setColor(QPalette.Window, QColor(53, 53, 53)) # self.p.setColor(QPalette.WindowText, Qt.white) # self.p.setColor(QPalette.AlternateBase, QColor(53, 53, 53)) # self.p.setColor(QPalette.ToolTipBase, Qt.white) # self.p.setColor(QPalette.ToolTipText, Qt.white) # self.p.setColor(QPalette.Button, QColor(53, 53, 53)) # self.p.setColor(QPalette.ButtonText, Qt.white) # self.p.setColor(QPalette.BrightText, Qt.red) # self.p.setColor(QPalette.Highlight, QColor(142, 45, 197).lighter()) # self.p.setColor(QPalette.HighlightedText, Qt.black) # self.setPalette(self.p) self.show()
def initUI(self): # QToolTip.setFont(QFont('SansSerif', 9)) self.cwidget = CameraCenterWidget() self.setCentralWidget(self.cwidget) # self.setToolTip('This is a <b>QWidget</b> widget') self.center() self.setWindowTitle('Camera Control GUI') self.statusBarTimer = QTimer(self) self.statusBarTimer.timeout.connect(self.statusUpdate) self.statusBarTimer.start(100) # self.p = QPalette(self.palette()) # self.p.setColor(QPalette.Window, QColor(53, 53, 53)) # self.p.setColor(QPalette.WindowText, Qt.white) # self.p.setColor(QPalette.AlternateBase, QColor(53, 53, 53)) # self.p.setColor(QPalette.ToolTipBase, Qt.white) # self.p.setColor(QPalette.ToolTipText, Qt.white) # self.p.setColor(QPalette.Button, QColor(53, 53, 53)) # self.p.setColor(QPalette.ButtonText, Qt.white) # self.p.setColor(QPalette.BrightText, Qt.red) # self.p.setColor(QPalette.Highlight, QColor(142, 45, 197).lighter()) # self.p.setColor(QPalette.HighlightedText, Qt.black) # self.setPalette(self.p) self.show()
def initUI(self): # QToolTip.setFont(QFont('SansSerif', 9)) self.cwidget = RGBCenterWidget() self.setCentralWidget(self.cwidget) # self.setToolTip('This is a <b>QWidget</b> widget') self.center() self.setWindowTitle('RGB Sensor GUI') self.statusBarTimer = QTimer(self) self.statusBarTimer.timeout.connect(self.statusUpdate) self.statusBarTimer.start(100) # self.p = QPalette(self.palette()) # self.p.setColor(QPalette.Window, QColor(53, 53, 53)) # self.p.setColor(QPalette.WindowText, Qt.white) # self.p.setColor(QPalette.AlternateBase, QColor(53, 53, 53)) # self.p.setColor(QPalette.ToolTipBase, Qt.white) # self.p.setColor(QPalette.ToolTipText, Qt.white) # self.p.setColor(QPalette.Button, QColor(53, 53, 53)) # self.p.setColor(QPalette.ButtonText, Qt.white) # self.p.setColor(QPalette.BrightText, Qt.red) # self.p.setColor(QPalette.Highlight, QColor(142, 45, 197).lighter()) # self.p.setColor(QPalette.HighlightedText, Qt.black) # self.setPalette(self.p) self.show()
def pen(self, color=Qt.black, style=Qt.SolidLine): pen = QPen(color) pen.setStyle(style) return pen
def draw(win): win.scene.clear() win.image.fill(black) tx = win.dial_x.value() ty = win.dial_y.value() tz = win.dial_z.value() if win.funcs.currentText() == "cos(x) * sin(z)": f = f1 if win.funcs.currentText() == "2 * cos(x * z)": f = f2 if win.funcs.currentText() == "exp(sin(sqrt(x^2 + z^2)))": f = f3 if win.funcs.currentText() == "x^2 / 20 + z^2 / 20": f = f4 if win.funcs.currentText() == "|sin(x) * sin(z)|": f = f5 win.image = float_horizon(win.scene.width(), win.scene.height(), win.x_min.value(), win.x_max.value(), win.dx.value(), win.z_min.value(), win.z_max.value(), win.dz.value(), tx, ty, tz, f, win.image) pix = QPixmap() pix.convertFromImage(win.image) win.scene.addPixmap(pix)
def add_point(point): global w if w.input_rect: w.pen.setColor(black) if w.point_now_rect is None: w.point_now_rect = point w.point_lock = point add_row(w.table_rect) i = w.table_rect.rowCount() - 1 item_x = QTableWidgetItem("{0}".format(point.x())) item_y = QTableWidgetItem("{0}".format(point.y())) w.table_rect.setItem(i, 0, item_x) w.table_rect.setItem(i, 1, item_y) else: w.edges.append(point) w.point_now_rect = point add_row(w.table_rect) i = w.table_rect.rowCount() - 1 item_x = QTableWidgetItem("{0}".format(point.x())) item_y = QTableWidgetItem("{0}".format(point.y())) w.table_rect.setItem(i, 0, item_x) w.table_rect.setItem(i, 1, item_y) item_x = w.table_rect.item(i-1, 0) item_y = w.table_rect.item(i-1, 1) w.scene.addLine(point.x(), point.y(), float(item_x.text()), float(item_y.text()), w.pen) if w.input_bars: w.pen.setColor(red) if w.point_now_bars is None: w.point_now_bars = point else: w.lines.append([[w.point_now_bars.x(), w.point_now_bars.y()], [point.x(), point.y()]]) add_row(w.table_bars) i = w.table_bars.rowCount() - 1 item_b = QTableWidgetItem("[{0}, {1}]".format(w.point_now_bars.x(), w.point_now_bars.y())) item_e = QTableWidgetItem("[{0}, {1}]".format(point.x(), point.y())) w.table_bars.setItem(i, 0, item_b) w.table_bars.setItem(i, 1, item_e) w.scene.addLine(w.point_now_bars.x(), w.point_now_bars.y(), point.x(), point.y(), w.pen) w.point_now_bars = None
def __init__(self): QtWidgets.QWidget.__init__(self) uic.loadUi("window.ui", self) self.scene = QtWidgets.QGraphicsScene(0, 0, 511, 511) self.mainview.setScene(self.scene) self.image = QImage(511, 511, QImage.Format_ARGB32_Premultiplied) self.pen = QPen() self.color_line = QColor(Qt.black) self.color_bground = QColor(Qt.white) self.draw_line.clicked.connect(lambda: draw_line(self)) self.clean_all.clicked.connect(lambda : clear_all(self)) self.btn_bground.clicked.connect(lambda: get_color_bground(self)) self.btn_line.clicked.connect(lambda: get_color_line(self)) self.draw_sun.clicked.connect(lambda: draw_sun(self)) self.cda.setChecked(True)
def get_color_line(win): color = QtWidgets.QColorDialog.getColor(initial=Qt.black, title='???? ?????', options=QtWidgets.QColorDialog.DontUseNativeDialog) if color.isValid(): win.color_line = color win.pen.setColor(color) s = QtWidgets.QGraphicsScene(0, 0, 10, 10) s.setBackgroundBrush(color) win.line_color.setScene(s)
def selectedChanged(self, state): if state: self.mainRect.setPen(QPen(Qt.red)) else: self.mainRect.setPen(QPen(Qt.black))
def __init__(self, parent=None): super(MpvWidget, self).__init__(parent) # Make the frame black, so that the video frame # is distinguishable from the rest when no # video is loaded yet self.setStyleSheet("background-color:black;") self.setMouseTracking(True) self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.contextMenu) self.cursortimer = QTimer(self) self.cursortimer.setSingleShot(True) self.cursortimer.timeout.connect(hideCursor)
def paintEvent(self, event): qp = QPainter(self) qp.setPen(Qt.black) size = self.size() for i in range(1024): x = random.randint(1, size.width()-1) y = random.randint(1, size.height()-1) qp.drawPoint(x, y)
def paintEvent(self, event): qp = QPainter(self) qp.setPen(Qt.black) size = self.size() # Colored rectangles qp.setBrush(QColor(200, 0, 0)) qp.drawRect(0, 0, 100, 100) qp.setBrush(QColor(0, 200, 0)) qp.drawRect(100, 0, 100, 100) qp.setBrush(QColor(0, 0, 200)) qp.drawRect(200, 0, 100, 100) # Color Effect for i in range(0,100): qp.setBrush(QColor(i*10, 0, 0)) qp.drawRect(10*i, 100, 10, 32) qp.setBrush(QColor(i*10, i*10, 0)) qp.drawRect(10*i, 100+32, 10, 32) qp.setBrush(QColor(i*2, i*10, i*1)) qp.drawRect(10*i, 100+64, 10, 32)
def draw(self, painter: QPainter) -> None: if self.sourceIsPixmap(): pixmap, offset = self.sourcePixmap(Qt.LogicalCoordinates, QGraphicsEffect.PadToEffectiveBoundingRect) else: pixmap, offset = self.sourcePixmap(Qt.DeviceCoordinates, QGraphicsEffect.PadToEffectiveBoundingRect) painter.setWorldTransform(QTransform()) painter.setBrush(Qt.black) painter.drawRect(pixmap.rect()) painter.setOpacity(self.opacity) painter.drawPixmap(offset, pixmap)
def paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex) -> None: r = option.rect pencolor = Qt.white if self.theme == 'dark' else Qt.black if self.parent.isEnabled(): if option.state & QStyle.State_Selected: painter.setBrush(QColor(150, 190, 78, 150)) elif option.state & QStyle.State_MouseOver: painter.setBrush(QColor(227, 212, 232)) pencolor = Qt.black else: brushcolor = QColor(79, 85, 87, 175) if self.theme == 'dark' else QColor('#EFF0F1') painter.setBrush(Qt.transparent if index.row() % 2 == 0 else brushcolor) painter.setPen(Qt.NoPen) painter.drawRect(r) thumb = QIcon(index.data(Qt.DecorationRole + 1)) starttime = index.data(Qt.DisplayRole + 1) endtime = index.data(Qt.UserRole + 1) externalPath = index.data(Qt.UserRole + 2) r = option.rect.adjusted(5, 0, 0, 0) thumb.paint(painter, r, Qt.AlignVCenter | Qt.AlignLeft) painter.setPen(QPen(pencolor, 1, Qt.SolidLine)) r = option.rect.adjusted(110, 8, 0, 0) painter.setFont(QFont('Noto Sans UI', 10 if sys.platform == 'darwin' else 8, QFont.Bold)) painter.drawText(r, Qt.AlignLeft, 'FILENAME' if len(externalPath) else 'START') r = option.rect.adjusted(110, 20, 0, 0) painter.setFont(QFont('Noto Sans UI', 11 if sys.platform == 'darwin' else 9, QFont.Normal)) if len(externalPath): painter.drawText(r, Qt.AlignLeft, self.clipText(os.path.basename(externalPath), painter)) else: painter.drawText(r, Qt.AlignLeft, starttime) if len(endtime) > 0: r = option.rect.adjusted(110, 45, 0, 0) painter.setFont(QFont('Noto Sans UI', 10 if sys.platform == 'darwin' else 8, QFont.Bold)) painter.drawText(r, Qt.AlignLeft, 'RUNTIME' if len(externalPath) else 'END') r = option.rect.adjusted(110, 60, 0, 0) painter.setFont(QFont('Noto Sans UI', 11 if sys.platform == 'darwin' else 9, QFont.Normal)) painter.drawText(r, Qt.AlignLeft, endtime) if self.parent.verticalScrollBar().isVisible(): self.parent.setFixedWidth(210) else: self.parent.setFixedWidth(190)
def _text_format(self, foreground=Qt.black, weight=QFont.Normal): fmt = QTextCharFormat() fmt.setForeground(QBrush(foreground)) fmt.setFontWeight(weight) return fmt
def paint(self, painter, option, widget): if not self.source or not self.dest: return # Draw the line itself. line = QLineF(self.sourcePoint, self.destPoint) if line.length() == 0.0: return painter.setPen(QPen(Qt.black, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) painter.drawLine(line) # Draw the arrows if there's enough room. angle = math.acos(line.dx() / line.length()) if line.dy() >= 0: angle = VGraphEdge.TwoPi - angle sourceArrowP1 = self.sourcePoint + QPointF(math.sin(angle + VGraphEdge.Pi / 3) * self.arrowSize, math.cos(angle + VGraphEdge.Pi / 3) * self.arrowSize) sourceArrowP2 = self.sourcePoint + QPointF(math.sin(angle + VGraphEdge.Pi - VGraphEdge.Pi / 3) * self.arrowSize, math.cos(angle + VGraphEdge.Pi - VGraphEdge.Pi / 3) * self.arrowSize); destArrowP1 = self.destPoint + QPointF(math.sin(angle - VGraphEdge.Pi / 3) * self.arrowSize, math.cos(angle - VGraphEdge.Pi / 3) * self.arrowSize) destArrowP2 = self.destPoint + QPointF(math.sin(angle - VGraphEdge.Pi + VGraphEdge.Pi / 3) * self.arrowSize, math.cos(angle - VGraphEdge.Pi + VGraphEdge.Pi / 3) * self.arrowSize) painter.setBrush(Qt.black) painter.drawPolygon(QPolygonF([line.p1(), sourceArrowP1, sourceArrowP2])) painter.drawPolygon(QPolygonF([line.p2(), destArrowP1, destArrowP2]))
def paintEvent(self, event): # pylint: disable=unused-argument painter = QPainter(self) painter.setPen(Qt.black) widgets = {w.get_id(): (self.top_point(w.geometry()), self.bottom_point(w.geometry())) for w in self.children() if isinstance(w, GoalWidget)} for widget_id, points in widgets.items(): line_start = points[0] for parent_widget in self.dependencies[widget_id]: line_end = widgets[parent_widget][1] painter.drawLine(line_start, line_end)
def paintEvent(self, paint_event): # pylint: disable=unused-argument painter = QPainter(self) painter.setRenderHint(painter.Antialiasing) painter.setPen(QColor(Qt.black)) for upper, lower in self.lines: x1, y1 = self._lower_bound(upper) x2, y2 = self._upper_bound(lower) painter.drawLine(x1, y1, x2, y2)
def __init__(self): super(GraphicsPathItem, self).__init__() pen = QPen() pen.setColor(Qt.black) pen.setWidth(10) self.setPen(pen)
def setGlyphColor(self, color): """ Sets the QColor_ *color* with which glyphs are rendered. The default is Qt.black. .. _QColor: http://doc.qt.io/qt-5/qcolor.html """ self._glyphColor = color self.update()
def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) for index in range(self._stick_count): if self.item_index >= index +1: painter.setPen(self.active_color) painter.setBrush(self.active_color) painter.drawRect(56+(index*100), 24, 76, 6) else: painter.setPen(self.passive_color) painter.setBrush(self.passive_color) painter.drawRect(56+(index*100), 24, 76, 6) for index in range(self._item_count): if self.item_index >= index: painter.setPen(self.active_color) painter.setBrush(self.active_color) painter.drawEllipse(32 + (index * 100), 16, 24, 24) painter.setPen(Qt.black) painter.drawText(32 + (index * 100), 16, 24, 84, Qt.AlignCenter | Qt.TextWordWrap | Qt.TextDontClip, self.parent.widget(index).windowTitle()) else: painter.setPen(self.passive_color) painter.setBrush(self.passive_color) painter.drawEllipse(32+(index*100), 16, 24, 24) painter.setPen(Qt.black) painter.drawText(32+(index*100), 16, 24, 84, Qt.AlignCenter | Qt.TextWordWrap | Qt.TextDontClip, self.parent.widget(index).windowTitle())
def paint(self, painter, option, widget): painter.setBrush(Qt.gray) painter.drawRect(-20, -58, 40, 2) # Front axel painter.drawRect(-20, 7, 40, 2) # Rear axel painter.setBrush(self.color) painter.drawRect(-25, -79, 50, 10) # Front wing painter.drawEllipse(-25, -48, 50, 20) # Side pods painter.drawRect(-25, -38, 50, 35) # Side pods painter.drawRect(-5, 9, 10, 10) # Back pod painter.drawEllipse(-10, -81, 20, 100) # Main body painter.drawRect(-17, 19, 34, 15) # Rear wing painter.setBrush(Qt.black) painter.drawPie(-5, -51, 10, 15, 0, 180 * 16) painter.drawRect(-5, -44, 10, 10) # Cockpit painter.save() painter.translate(-20, -58) painter.rotate(self.wheelsAngle) painter.drawRect(-10, -7, 10, 15) # Front left painter.restore() painter.save() painter.translate(20, -58) painter.rotate(self.wheelsAngle) painter.drawRect(0, -7, 10, 15) # Front right painter.restore() painter.drawRect(-30, 0, 12, 17) # Rear left painter.drawRect(19, 0, 12, 17) # Rear right
def brushChanged(self): style = Qt.BrushStyle(self.brushStyleComboBox.itemData( self.brushStyleComboBox.currentIndex(), IdRole)) if style == Qt.LinearGradientPattern: linearGradient = QLinearGradient(0, 0, 100, 100) linearGradient.setColorAt(0.0, Qt.white) linearGradient.setColorAt(0.2, Qt.green) linearGradient.setColorAt(1.0, Qt.black) self.renderArea.setBrush(QBrush(linearGradient)) elif style == Qt.RadialGradientPattern: radialGradient = QRadialGradient(50, 50, 50, 70, 70) radialGradient.setColorAt(0.0, Qt.white) radialGradient.setColorAt(0.2, Qt.green) radialGradient.setColorAt(1.0, Qt.black) self.renderArea.setBrush(QBrush(radialGradient)) elif style == Qt.ConicalGradientPattern: conicalGradient = QConicalGradient(50, 50, 150) conicalGradient.setColorAt(0.0, Qt.white) conicalGradient.setColorAt(0.2, Qt.green) conicalGradient.setColorAt(1.0, Qt.black) self.renderArea.setBrush(QBrush(conicalGradient)) elif style == Qt.TexturePattern: self.renderArea.setBrush(QBrush(QPixmap(':/images/brick.png'))) else: self.renderArea.setBrush(QBrush(Qt.green, style))
def __init__(self, parent=None): super(GLWidget, self).__init__(parent) self.clearColor = QColor(Qt.black) self.xRot = 0 self.yRot = 0 self.zRot = 0 self.program = None self.lastPos = QPoint()
def paintEvent(self, event): painter = QPainter(self) painter.fillRect(event.rect(), Qt.white) painter.setFont(self.displayFont) redrawRect = event.rect() beginRow = redrawRect.top() // self.squareSize endRow = redrawRect.bottom() // self.squareSize beginColumn = redrawRect.left() // self.squareSize endColumn = redrawRect.right() // self.squareSize painter.setPen(Qt.gray) for row in range(beginRow, endRow + 1): for column in range(beginColumn, endColumn + 1): painter.drawRect(column * self.squareSize, row * self.squareSize, self.squareSize, self.squareSize) fontMetrics = QFontMetrics(self.displayFont) painter.setPen(Qt.black) for row in range(beginRow, endRow + 1): for column in range(beginColumn, endColumn + 1): key = row * self.columns + column painter.setClipRect(column * self.squareSize, row * self.squareSize, self.squareSize, self.squareSize) if key == self.lastKey: painter.fillRect(column * self.squareSize + 1, row * self.squareSize + 1, self.squareSize, self.squareSize, Qt.red) key_ch = self._chr(key) painter.drawText(column * self.squareSize + (self.squareSize / 2) - fontMetrics.width(key_ch) / 2, row * self.squareSize + 4 + fontMetrics.ascent(), key_ch)
def createColorComboBox(self): comboBox = QComboBox() comboBox.addItem("Red", Qt.red) comboBox.addItem("Blue", Qt.blue) comboBox.addItem("Black", Qt.black) comboBox.addItem("Magenta", Qt.magenta) return comboBox
def drawBackgroundToPixmap(self): r = self.scene.sceneRect() self.background = QPixmap(qRound(r.width()), qRound(r.height())) self.background.fill(Qt.black) painter = QPainter(self.background) bg = QImage(self.imagesDir + '/demobg.png') painter.drawImage(0, 0, bg)
def paintEvent(self, event): qp = QPainter() qp.begin(self) qp.fillRect(self.rect(), Qt.black) self.img = self.render_image() self.rect_x = (self.rect().width() / 2) - ((self.maxPixelsPerLine * self.pixelSize) / 2) qp.drawImage(QRect(QPoint(self.rect_x, 0), QPoint(self.rect_x + self.maxPixelsPerLine * self.pixelSize, (self.maxPixelsTotal / self.maxPixelsPerLine) * self.pixelSize)), self.img) qp.end()
def createEditor(self, parent: QWidget, option: QStyleOptionViewItem, index: QModelIndex): editor = QComboBox(parent) if sys.platform == "win32": # Ensure text entries are visible with windows combo boxes editor.setMinimumHeight(self.sizeHint(option, index).height() + 10) editor.addItems(self.items) if self.is_editable: editor.setEditable(True) editor.setInsertPolicy(QComboBox.NoInsert) if self.current_edit_text: editor.setEditText(self.current_edit_text) if self.colors: img = QImage(16, 16, QImage.Format_RGB32) painter = QPainter(img) painter.fillRect(img.rect(), Qt.black) rect = img.rect().adjusted(1, 1, -1, -1) for i, item in enumerate(self.items): color = self.colors[i] painter.fillRect(rect, QColor(color.red(), color.green(), color.blue(), 255)) editor.setItemData(i, QPixmap.fromImage(img), Qt.DecorationRole) del painter editor.currentIndexChanged.connect(self.currentIndexChanged) editor.editTextChanged.connect(self.on_edit_text_changed) return editor
def __init__(self, parent=None): super(VideoWidget, self).__init__(parent) self.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored) p = self.palette() p.setColor(QPalette.Window, Qt.black) self.setPalette(p) self.setAttribute(Qt.WA_OpaquePaintEvent)