def paintEvent(self, event): """Override QProgressBar's paintEvent.""" if self.text() != self._default_label.text(): self._default_label.setText(self.text()) if self.isTextVisible() != self._default_label.isVisible(): self._default_label.setVisible(self.isTextVisible()) percent = utils.get_percent(self.value(), self.minimum(), self.maximum()) total_width = self.get_dayu_width() pen_width = int(3 * total_width / 50.0) radius = total_width - pen_width - 1 painter = QPainter(self) painter.setRenderHints(QPainter.Antialiasing) # draw background circle pen_background = QPen() pen_background.setWidth(pen_width) pen_background.setColor(QColor(dayu_theme.background_selected_color)) pen_background.setCapStyle(Qt.RoundCap) painter.setPen(pen_background) painter.drawArc(pen_width / 2.0 + 1, pen_width / 2.0 + 1, radius, radius, self._start_angle, -self._max_delta_angle) # draw foreground circle pen_foreground = QPen() pen_foreground.setWidth(pen_width) pen_foreground.setColor(QColor(self._color)) pen_foreground.setCapStyle(Qt.RoundCap) painter.setPen(pen_foreground) painter.drawArc(pen_width / 2.0 + 1, pen_width / 2.0 + 1, radius, radius, self._start_angle, -percent * 0.01 * self._max_delta_angle) painter.end()
def paintEvent(self, event): """override the paint event to paint the 1/4 circle image.""" painter = QPainter(self) painter.setRenderHint(QPainter.SmoothPixmapTransform) painter.translate(self.pix.width() / 2, self.pix.height() / 2) painter.rotate(self._rotation) painter.drawPixmap(-self.pix.width() / 2, -self.pix.height() / 2, self.pix.width(), self.pix.height(), self.pix) painter.end() return super(MLoading, self).paintEvent(event)
def draw_empty_content(view, text=None, pix_map=None): from dayu_widgets import dayu_theme pix_map = pix_map or MPixmap('empty.svg') text = text or view.tr('No Data') painter = QPainter(view) font_metrics = painter.fontMetrics() painter.setPen(QPen(dayu_theme.secondary_text_color)) content_height = pix_map.height() + font_metrics.height() padding = 10 proper_min_size = min(view.height() - padding * 2, view.width() - padding * 2, content_height) if proper_min_size < content_height: pix_map = pix_map.scaledToHeight(proper_min_size - font_metrics.height(), Qt.SmoothTransformation) content_height = proper_min_size painter.drawText(view.width() / 2 - font_metrics.width(text) / 2, view.height() / 2 + content_height / 2 - font_metrics.height() / 2, text) painter.drawPixmap(view.width() / 2 - pix_map.width() / 2, view.height() / 2 - content_height / 2, pix_map) painter.end()