def pixmap(pixmap_path, color=None): """ Returns Qt pixmap instance :param pixmap_path: Path were pixmap resource is located :param color: :return: New instance of a Qt pixmap :rtype: QtGui.QPixmap """ if color and isinstance(color, str): from artella.widgets import color as artella_color color = artella_color.from_string(color) new_pixmap = QtGui.QPixmap(pixmap_path) if not new_pixmap.isNull() and color: painter = QtGui.QPainter(new_pixmap) painter.setCompositionMode(QtGui.QPainter.CompositionMode_SourceIn) painter.setBrush(color) painter.setPen(color) painter.drawRect(new_pixmap.rect()) painter.end() return new_pixmap
def paintEvent(self, event): 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._width pen_width = int(3 * total_width / 50.0) radius = total_width - pen_width - 1 painter = QtGui.QPainter(self) painter.setRenderHints(QtGui.QPainter.Antialiasing) # draw background circle pen_background = QtGui.QPen() pen_background.setWidth(pen_width) pen_background.setColor(QtGui.QColor(80, 120, 110)) pen_background.setCapStyle(QtCore.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 = QtGui.QPen() pen_foreground.setWidth(pen_width) pen_foreground.setColor(self._color) pen_foreground.setCapStyle(QtCore.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()