Example #1
0
    def paintEvent(self, arg__1: QPaintEvent):
        # super(Push, self).paintEvent(arg__1)
        # lightgrey
        painter = QPainter()
        painter.begin(self)
        pen = QPen(QColor(162, 181, 205), 2, Qt.SolidLine)
        painter.setBrush(QBrush(QColor(255, 255, 255)))
        painter.setPen(pen)
        painter.setRenderHint(QPainter.Antialiasing, True)
        rect = QRect()
        rect.moveTo(1, 10)
        rect.setWidth(140)
        rect.setHeight(140)
        painter.drawRoundedRect(rect, 5, 5)
        painter.drawConvexPolygon(
            [QPoint(60, 10), QPoint(80, 10),
             QPoint(70, 1)])

        pen.setColor(QColor(255, 255, 255))
        painter.setPen(pen)
        painter.drawLine(63, 10, 77, 10)
        pen.setWidth(1)
        painter.setPen(pen)
        painter.drawPoints([QPoint(61, 10), QPoint(78, 10)])
        painter.end()
Example #2
0
    def paintEvent(self, event: QPaintEvent):
        painter = QPainter(self)

        painter.fillRect(event.rect(), self.palette().base())

        if self.level is None:
            return

        total_length = max(self.current_value, self.original_value)

        pixels_per_byte = event.rect().width() / total_length

        bar = QRect(event.rect())
        bar.setWidth(pixels_per_byte * self.current_value)

        if self.current_value > self.original_value:
            painter.fillRect(bar, Qt.red)
        else:
            painter.fillRect(bar, self.value_color)
    def paint(self, painter, option, index):
        # data is our status dict, containing progress, id, status
        job_id, data = index.model().data(index, Qt.DisplayRole)
        if data["progress"] > 0:
            color = QColor(STATUS_COLORS[data["status"]])

            brush = QBrush()
            brush.setColor(color)
            brush.setStyle(Qt.SolidPattern)

            width = option.rect.width() * data["progress"] / 100

            rect = QRect(option.rect)  #  Copy of the rect, so we can modify.
            rect.setWidth(width)

            painter.fillRect(rect, brush)

        pen = QPen()
        pen.setColor(Qt.black)
        painter.drawText(option.rect, Qt.AlignLeft, job_id)
Example #4
0
    def paintEvent(self, arg__1: PySide2.QtGui.QPaintEvent):
        painter = QPainter(self.viewport())
        painter.translate(
            -self.horizontalScrollBar().value() * self.font_width, 0)

        # Pixel offset of this row
        row_y = 0

        # Starting byte offset
        offset = self.verticalScrollBar().value() * self.row_width

        painter.fillRect(self.viewport().rect(), self.palette().base())

        offset_rect = QRect(self.viewport().rect())
        offset_rect.setWidth(self._offset_width_pixels())
        painter.fillRect(offset_rect, self.palette().window())

        ascii_rect = QRect(self.viewport().rect())
        ascii_rect.setX(ascii_rect.x() + self._offset_width_pixels() +
                        self._hex_width_pixels() + 96)
        ascii_rect.setWidth(2)
        painter.fillRect(ascii_rect, self.palette().window())

        if not self.data:
            return None

        widget_height = self.height()
        leading = self.fontMetrics().leading()

        painter.save()

        while row_y + self.line_height < widget_height and offset < len(
                self.data):
            self._draw_row(painter, offset, row_y)
            offset += self.row_width
            row_y += self.line_height + leading

        painter.restore()
    def mouseMoveEvent(self, event: QMouseEvent) -> None:
        """Qt Mouse-Move Event"""
        def get_top_resize_values() -> Tuple[int, int]:
            """calculates vertial position and height"""
            py: int = (event.globalPos() - self.__mouse_pos).y()
            if self.__window_geometry_height - py < self.__parent.minimumSize(
            ).height():
                height: int = self.__parent.minimumSize().height()
                pos_y: int = self.__window_pos_y + self.__window_geometry_height - height
            else:
                height = self.__window_geometry_height - py
                pos_y = self.__window_pos_y + py
            return pos_y, height

        def get_left_resize_values() -> Tuple[int, int]:
            """calculates horizontal position and width"""
            px: int = (event.globalPos() - self.__mouse_pos).x()
            if self.__window_geometry_width - px < self.__parent.minimumSize(
            ).width():
                width: int = self.__parent.minimumSize().width()
                pos_x: int = self.__window_pos_x + self.__window_geometry_width - width
            else:
                width = self.__window_geometry_width - px
                pos_x = self.__window_pos_x + px
            return pos_x, width

        if self.__mouse_pressed:
            if self.__type == self.BOTTOM:
                py = (event.globalPos() - self.__mouse_pos).y()
                geometry = QRect(self.__window_geometry_x,
                                 self.__window_geometry_y,
                                 self.__window_geometry_width,
                                 self.__window_geometry_height + py)
            elif self.__type == self.RIGHT:
                px = (event.globalPos() - self.__mouse_pos).x()
                geometry = QRect(self.__window_geometry_x,
                                 self.__window_geometry_y,
                                 self.__window_geometry_width + px,
                                 self.__window_geometry_height)
            elif self.__type == self.TOP:
                pos_y, height = get_top_resize_values()
                geometry = QRect(self.__window_geometry_x, pos_y,
                                 self.__window_geometry_width, height)
            elif self.__type == self.LEFT:
                pos_x, width = get_left_resize_values()
                geometry = QRect(pos_x, self.__window_geometry_y, width,
                                 self.__window_geometry_height)
            elif self.__type == self.TOP_LEFT:
                pos_x, width = get_left_resize_values()
                pos_y, height = get_top_resize_values()
                geometry = QRect(pos_x, pos_y, width, height)
            elif self.__type == self.TOP_RIGHT:
                px = (event.globalPos() - self.__mouse_pos).x()
                pos_y, height = get_top_resize_values()
                geometry = QRect(self.__window_pos_x, pos_y,
                                 self.__window_geometry_width + px, height)
            elif self.__type == self.BOTTOM_LEFT:
                pos_x, width = get_left_resize_values()
                py = (event.globalPos() - self.__mouse_pos).y()
                geometry = QRect(pos_x, self.__window_pos_y, width,
                                 self.__window_geometry_height + py)
            elif self.__type == self.BOTTOM_RIGHT:
                px = (event.globalPos() - self.__mouse_pos).x()
                py = (event.globalPos() - self.__mouse_pos).y()
                geometry = QRect(self.__window_geometry_x,
                                 self.__window_geometry_y,
                                 self.__window_geometry_width + px,
                                 self.__window_geometry_height + py)
            if geometry.width() < self.__parent.minimumSize().width():
                geometry.setWidth(self.__parent.minimumSize().width())
            if geometry.height() < self.__parent.minimumSize().height():
                geometry.setHeight(self.__parent.minimumSize().height())
            self.__parent.setGeometry(geometry)
            self.adjust_resizers(geometry)