def _paint(self, dst: QImage): """Retrieve QPainter for the given surface.""" p = QPainter(dst) p.setPen(Qt.NoPen) # Set the bounding rectangle if present. if self.bounds: x = self.bounds.left y = self.bounds.top w = self.bounds.right - x h = self.bounds.bottom - y p.setClipRect(x, y, w + 1, h + 1) p.setClipping(True) return p
def paintEvent(self, event): side = min(self.width(), self.height()) curr_time = self._time painter = QPainter() painter.begin(self) painter.setRenderHint(QPainter.Antialiasing) painter.translate(self.width() / 2, self.height() / 2) # draw clock frame painter.setBrush(QBrush(self.background_color)) r = side / 2 painter.drawEllipse(QPoint(0, 0), side / 2, side / 2) for i in range(0, 12): x, y = self.rotate_point(0, -r * 0.95, i * 360 / 12) painter.drawEllipse(x - 3, y - 3, 6, 6) painter.setPen(self.text_color) for i in range(0, 12): x, y = self.rotate_point(0, -r * 0.85, i * 360 / 12) painter.drawText(QRect(x - 10, y - 10, 20, 20), Qt.AlignCenter, "%d" % i) painter.setPen(self.background_color) painter.setBrush(QBrush(self.min_pin_color)) for j in range(0, 60): if j % 5 != 0: x, y = self.rotate_point(0, -r * 0.95, j * 360 / 60) painter.drawEllipse(x - 1, y - 1, 2, 2) painter.setClipping(False) # draw hands painter.setBrush(QBrush(self.hour_pin_color)) painter.save() self.hour_pin[2] = QPoint(0, int(-r * 0.6)) painter.rotate(30.0 * (curr_time.hour() + curr_time.minute() / 60.0)) painter.drawConvexPolygon(self.hour_pin) painter.restore() painter.setBrush(QBrush(self.min_pin_color)) painter.save() self.minute_pin[2] = QPoint(0, int(-r * 0.9)) painter.rotate(6.0 * (curr_time.minute() + curr_time.second() / 60.0)) painter.drawConvexPolygon(self.minute_pin) painter.restore() painter.end()
def paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex): """Apply graphical formatting to each item in each displayed column in the view""" brush = QBrush() pen = QPen() font = QFont() if option.state & QStyle.State_Selected: text_color = option.palette.color(QPalette.Normal, QPalette.BrightText) else: text_color = option.palette.color(QPalette.Normal, QPalette.Text) is_selected = option.state & QStyle.State_Selected # Default theme color pen.setColor(text_color) field_name = self.field_name(index).lower() value = self.value(index) # Colour bases (default color is the one of the current theme) if (field_name == "ref" or field_name == "alt") and (value in ("A", "C", "G", "T") and not is_selected): pen.setColor( self.BASE_COLOR.get(value, option.palette.color(QPalette.WindowText))) if field_name == "impact" and not is_selected: font.setBold(True) pen.setColor( self.IMPACT_COLOR.get(value, self.IMPACT_COLOR["MODIFIER"])) if field_name == "gene" and not is_selected: pen.setColor("#6a9fca") if field_name == "classification": icon = self.ACMG_ICON.get(str(value), self.ACMG_ICON["0"]) self.draw_icon(painter, option.rect, icon) return if field_name == "favorite": icon = self.FAV_ICON.get(int(value), self.FAV_ICON[0]) self.draw_icon(painter, option.rect, icon) return if field_name == "hgvs_c": font.setBold(True) m = re.search(r"([cnm]\..+)", str(value)) if m: value = m.group(1) if field_name == "hgvs_p": font.setBold(True) m = re.search(r"(p\..+)", str(value)) if m: value = m.group(1) if re.match(r"sample\[.+\]\.gt", field_name): icon = self.GENOTYPE_ICONS.get(int(value), self.GENOTYPE_ICONS[-1]) self.draw_icon(painter, option.rect, icon) return if field_name == "consequence": values = str(self.value(index)).split("&") metrics = QFontMetrics(font) x = option.rect.x() + 5 # y = option.rect.center().y() for value in values: width = metrics.width(value) height = metrics.height() rect = QRect(x, 0, width + 15, height + 10) rect.moveCenter(option.rect.center()) rect.moveLeft(x) painter.setFont(font) painter.setClipRect(option.rect, Qt.IntersectClip) painter.setBrush( QBrush(QColor(self.SO_COLOR.get(value, "#90d4f7")))) painter.setPen(Qt.NoPen) painter.drawRoundedRect(rect, 3, 3) painter.setPen(QPen(QColor("white"))) painter.drawText(rect, Qt.AlignCenter | Qt.AlignVCenter, value) x += width + 20 painter.setClipping(False) return if field_name == "rsid": self.draw_url(painter, option.rect, value, QUrl("http://www.google.fr"), index) return painter.setBrush(brush) painter.setPen(pen) painter.setFont(font) painter.drawText(option.rect, option.displayAlignment, value)
def paintEvent(self, event): p = QPainter() p.begin(self) self._normalMap.render(p, event.rect()) p.setPen(Qt.black) # p.drawText(self.rect(), Qt.AlignBottom | Qt.TextWordWrap, "Map data CCBYSA 2009 OpenStreetMap.org contributors") p.end() if self.zoomed: dim = min(self.width(), self.height()) magnifierSize = min(MAX_MAGNIFIER, dim * 2 / 3) radius = magnifierSize / 2 ring = radius - 15 box = QSize(magnifierSize, magnifierSize) # reupdate our mask if self.maskPixmap.size() != box: self.maskPixmap = QPixmap(box) self.maskPixmap.fill(Qt.transparent) g = QRadialGradient() g.setCenter(radius, radius) g.setFocalPoint(radius, radius) g.setRadius(radius) g.setColorAt(1.0, QColor(255, 255, 255, 0)) g.setColorAt(0.5, QColor(128, 128, 128, 255)) mask = QPainter(self.maskPixmap) mask.setRenderHint(QPainter.Antialiasing) mask.setCompositionMode(QPainter.CompositionMode_Source) mask.setBrush(g) mask.setPen(Qt.NoPen) mask.drawRect(self.maskPixmap.rect()) mask.setBrush(QColor(Qt.transparent)) mask.drawEllipse(g.center(), ring, ring) mask.end() center = self.dragPos - QPoint(0, radius) center += QPoint(0, radius / 2) corner = center - QPoint(radius, radius) xy = center * 2 - QPoint(radius, radius) # only set the dimension to the magnified portion if self.zoomPixmap.size() != box: self.zoomPixmap = QPixmap(box) self.zoomPixmap.fill(Qt.lightGray) if True: p = QPainter(self.zoomPixmap) p.translate(-xy) self._largeMap.render(p, QRect(xy, box)) p.end() clipPath = QPainterPath() clipPath.addEllipse(QPointF(center), ring, ring) p = QPainter(self) p.setRenderHint(QPainter.Antialiasing) p.setClipPath(clipPath) p.drawPixmap(corner, self.zoomPixmap) p.setClipping(False) p.drawPixmap(corner, self.maskPixmap) p.setPen(Qt.gray) p.drawPath(clipPath) if self.invert: p = QPainter(self) p.setCompositionMode(QPainter.CompositionMode_Difference) p.fillRect(event.rect(), Qt.white) p.end()