我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用PyQt5.QtCore.Qt.gray()。
def add_crosshair(plot, render_measurements, color=Qt.gray): pen = mkPen(color=QColor(color), width=1) vline = InfiniteLine(angle=90, movable=False, pen=pen) hline = InfiniteLine(angle=0, movable=False, pen=pen) plot.addItem(vline, ignoreBounds=True) plot.addItem(hline, ignoreBounds=True) current_coordinates = None reference_coordinates = None def do_render(): render_measurements(current_coordinates, reference_coordinates) def update(pos): nonlocal current_coordinates if plot.sceneBoundingRect().contains(pos): mouse_point = plot.getViewBox().mapSceneToView(pos) current_coordinates = mouse_point.x(), mouse_point.y() vline.setPos(mouse_point.x()) hline.setPos(mouse_point.y()) do_render() def set_reference(ev): nonlocal reference_coordinates if ev.button() == Qt.LeftButton and current_coordinates is not None: reference_coordinates = current_coordinates do_render() plot.scene().sigMouseMoved.connect(update) plot.scene().sigMouseClicked.connect(set_reference)
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 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 setStatusColor(self, rowIndex): """????????""" item = self.tableWidget.item(rowIndex, 6) if item.text() == "normal": item.setForeground(Qt.darkGreen) elif item.text() == "update": item.setForeground(Qt.darkRed) elif item.text() == "error": item.setForeground(Qt.darkYellow) elif item.text() == "none": item.setForeground(Qt.gray)
def __init__(self, parent=None): super().__init__(parent) width, height = 800, 800 self.setGeometry(width, height, width, height) # configs, can be changed at runtime self.circle_line_color = Qt.gray self.crosshair_line_color = Qt.gray self.text_label_color = Qt.darkGreen self.measured_distances_color = Qt.green self.circle_count = 10 self.dot_width = 10 self.line_width = 1 self.distance_measurement_angle = 15 self.measurement_angle = 10 # degrees that one sensor covers self.fade_out_time = 4 # older measurements will fade out over this time self.add_text_labels = False # data self.measurements = [] self.added_time = dict() # measurement -> timestamp # drawing timer self.timer = QTimer() self.timer.setInterval(80) self.timer.timeout.connect(self.draw_radar) self.timer.start() # internal canvas setup self.layout = QHBoxLayout() self.setLayout(self.layout) self.scene = QGraphicsScene() self.scene.setSceneRect(0, 0, width, height) self.canvas = QGraphicsView() self.canvas.setRenderHint(QPainter.Antialiasing) self.canvas.setFixedSize(width, height) self.canvas.setAlignment(Qt.AlignLeft) self.canvas.setScene(self.scene) self.canvas.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.canvas.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.layout.addWidget(self.canvas) # initial rendering self.draw_radar()