Exemplo n.º 1
0
    def paintEvent(self, event):
        super().paintEvent(event)
        rect = QLine(self.x0, self.y0, self.x1, self.y1)

        painter = QPainter(self)
        painter.setPen(QPen(Qt.red, 2, Qt.SolidLine))
        painter.drawLine(rect)
Exemplo n.º 2
0
    def paintEvent(self, event):
        rect = QRect(10, 20, 80, 60)

        path = QPainterPath()
        path.moveTo(20, 80)
        path.lineTo(20, 30)
        path.cubicTo(80, 0, 50, 50, 80, 80)

        startAngle = 30 * 16
        arcLength = 120 * 16

        painter = QPainter(self)
        painter.setPen(self.pen)
        painter.setBrush(self.brush)
        if self.antialiased:
            painter.setRenderHint(QPainter.Antialiasing)

        for x in range(0, self.width(), 100):
            for y in range(0, self.height(), 100):
                painter.save()
                painter.translate(x, y)
                if self.transformed:
                    painter.translate(50, 50)
                    painter.rotate(60.0)
                    painter.scale(0.6, 0.9)
                    painter.translate(-50, -50)

                if self.shape == RenderArea.Line:
                    painter.drawLine(rect.bottomLeft(), rect.topRight())
                elif self.shape == RenderArea.Points:
                    painter.drawPoints(RenderArea.points)
                elif self.shape == RenderArea.Polyline:
                    painter.drawPolyline(RenderArea.points)
                elif self.shape == RenderArea.Polygon:
                    painter.drawPolygon(RenderArea.points)
                elif self.shape == RenderArea.Rect:
                    painter.drawRect(rect)
                elif self.shape == RenderArea.RoundedRect:
                    painter.drawRoundedRect(rect, 25, 25, Qt.RelativeSize)
                elif self.shape == RenderArea.Ellipse:
                    painter.drawEllipse(rect)
                elif self.shape == RenderArea.Arc:
                    painter.drawArc(rect, startAngle, arcLength)
                elif self.shape == RenderArea.Chord:
                    painter.drawChord(rect, startAngle, arcLength)
                elif self.shape == RenderArea.Pie:
                    painter.drawPie(rect, startAngle, arcLength)
                elif self.shape == RenderArea.Path:
                    painter.drawPath(path)
                elif self.shape == RenderArea.Text:
                    painter.drawText(rect, Qt.AlignCenter,
                                     "PySide 2\nQt %s" % qVersion())
                elif self.shape == RenderArea.Pixmap:
                    painter.drawPixmap(10, 10, self.pixmap)

                painter.restore()

        painter.setPen(self.palette().dark().color())
        painter.setBrush(Qt.NoBrush)
        painter.drawRect(QRect(0, 0, self.width() - 1, self.height() - 1))
Exemplo n.º 3
0
 def draw(self, painter: QPainter):
     super().draw(painter)
     pen = painter.pen()
     pen.setColor(QColor('darkgrey'))
     painter.setPen(pen)
     w = self.width
     h = self.height
     painter.drawLine(w//2, h*3//4, w*13//14, h*3//12)
Exemplo n.º 4
0
 def draw(self, painter: QPainter):
     super().draw(painter)
     w = self.width
     h = self.height
     length = int(self.width * 0.32)
     x = int(w * 0.28)
     y = int(h * 0.7)
     painter.drawLine(x, y, x + length, y - length)
Exemplo n.º 5
0
 def draw(self, painter: QPainter):
     super().draw(painter)
     pen = painter.pen()
     pen.setColor(QColor('darkgrey'))
     painter.setPen(pen)
     w = self.width
     h = self.height
     x = int(w * 0.71)
     painter.drawLine(x, int(h * 0.48), x, int(h * 0.7))
Exemplo n.º 6
0
 def draw(self, painter: QPainter):
     super().draw(painter)
     pen = painter.pen()
     pen.setColor(QColor('darkgrey'))
     painter.setPen(pen)
     w = self.width
     h = self.height
     length = int(w * 0.2)
     x = int(w * 0.4)
     y = int(h * 0.58)
     painter.drawLine(x, y, x + length, y - length)
Exemplo n.º 7
0
 def draw(self, painter: QPainter):
     super().draw(painter)
     pen = painter.pen()
     pen.setColor(QColor('darkgrey'))
     painter.setPen(pen)
     w = self.width
     h = self.height
     size = int(w * 0.06)
     x = int(w * 0.49)
     y = int(h * 0.47)
     painter.drawLine(x, y - size, x, y + size)
     painter.drawLine(x - size, y, x + size, y)
     x = int(w * 0.6)
     y = int(h * 0.37)
     painter.drawLine(x, y - size, x, y + size)
     painter.drawLine(x - size, y, x + size, y)
Exemplo n.º 8
0
    def paint(self, painter: QPainter, option: QStyleOptionViewItem,
              index: QModelIndex) -> None:
        itemOption = QStyleOptionViewItem(option)

        # disable focus outline
        if itemOption.state & QStyle.State_HasFocus:
            itemOption.state ^= QStyle.State_HasFocus
        # hover whole row
        if index.row() == option.styleObject.hoverIndexRow:
            itemOption.state |= QStyle.State_MouseOver

        super().paint(painter, itemOption, index)

        # draw lines around numeric columns
        if index.column() in (5, 12):
            oldpen = painter.pen()
            painter.setPen(self.linepen)
            painter.drawLine(itemOption.rect.topRight() + QPoint(0, 0),
                             itemOption.rect.bottomRight() + QPoint(0, 0))
            painter.setPen(oldpen)
 def shape_to_pixelmap(item_type, pen, brush, shape) -> QPixmap:
     pixmap = QPixmap(50, 50)
     pixmap.fill(Qt.transparent)
     painter = QPainter(pixmap)
     painter.setRenderHint(QPainter.Antialiasing)
     painter.setPen(pen)
     painter.setBrush(brush)
     if item_type == QGraphicsRectItem.type(QGraphicsRectItem()):
         painter.drawRect(QRect(10, 15, 30, 20))
     elif item_type == QGraphicsEllipseItem.type(QGraphicsEllipseItem()):
         painter.drawEllipse(QRect(10, 10, 30, 30))
     elif item_type == QGraphicsPolygonItem.type(QGraphicsPolygonItem()):
         if shape.polygon().size() == 3:
             painter.drawPolygon(QPolygon([QPoint(10, 40), QPoint(40, 40), QPoint(25, 10)]))
         else:
             painter.drawPolygon(QPolygon([QPoint(12, 40), QPoint(23, 36),
                                           QPoint(37, 24), QPoint(23, 12), QPoint(7, 16)]))
     elif item_type == QGraphicsLineItem.type(QGraphicsLineItem()):
         painter.drawLine(QLine(10, 40, 40, 10))
     return pixmap
Exemplo n.º 10
0
    def DrawWidget(self, Painter: QtGui.QPainter, Option, Index):
        state = Option.state

        if state & self._style.State_Enabled and state & self._style.State_Selected:
            # Selected
            color = QtGui.QColor(self._theme.get("ui-02"))
            border = QtGui.QColor(self._theme.get("ui-01"))

        elif state & self._style.State_Enabled and state & self._style.State_Active:
            # Normal
            color = QtGui.QColor(self._theme.get("ui-01"))
            border = QtGui.QColor(self._theme.get("ui-02"))

        elif state & self._style.State_Enabled:
            # Inactive
            color = QtGui.QColor(self._theme.get("ui-01"))
            border = QtGui.QColor(self._theme.get("ui-02"))

        else:
            # Disabled
            color = QtGui.QColor(self._theme.get("disabled-02"))
            border = QtGui.QColor(self._theme.get("disabled-02"))

        Painter.setPen(color)
        self._style.drawPrimitive(self._style.PE_PanelItemViewItem, Option, Painter, Option.widget)
        Painter.fillRect(Option.rect, (color))

        Painter.setPen(QtGui.QColor(self._theme.get("text-02")))
        items = self.getData(Index)
        self.DrawCover(Painter, Option)
        self.DrawTop(Painter, Option, items[0])
        self.DrawMid(Painter, Option, items[1])
        self.DrawBottom(Painter, Option, [items[2], items[3], items[4]])

        Painter.setPen(border)
        Painter.drawLine(QPoint(0, Option.rect.y() + 63), QPoint(Option.rect.width(), Option.rect.y() + 63))
Exemplo n.º 11
0
 def draw(self, painter: QPainter):
     super().draw(painter)
     w = self.width
     h = self.height
     painter.drawLine(w//6, h//6, w*5//6, h*5//6)
Exemplo n.º 12
0
 def draw(self, painter: QPainter):
     super().draw(painter)
     w = self.width
     h = self.height
     y = int(h * 0.59)
     painter.drawLine(int(w * 0.18), y, int(w * 0.81), y)
Exemplo n.º 13
0
 def draw(self, painter: QPainter):
     super().draw(painter)
     w = self.width
     h = self.height
     x = int(w * 0.28)
     painter.drawLine(x, int(h * 0.26), x, int(h * 0.7))
Exemplo n.º 14
0
    def paintEvent(self, event):

        paint = QPainter()
        paint.begin(self)
        paint.save()

        size = self.size()
        width = size.width()
        height = size.height()
        units = self.data.get('units')

        proportion = self.getProportion()

        horizontalOrientation = self.data.get('horizontal_orientation')

        if horizontalOrientation:

            rulerLength = width
            traceLengthLimit = height

        else:  # vertical orientation
            rulerLength = height
            traceLengthLimit = width

            paint.translate(width, 0)
            paint.rotate(90)

            # the length of the traces (lines)
        small = traceLengthLimit / 6
        medium = traceLengthLimit / 4
        large = traceLengthLimit / 3

        limit = rulerLength / proportion

        # draw less lines for centimeters
        if units == 'cm':
            step = 10

        else:
            step = 5

        # begin drawing
        fontSize = 10
        font = QFont('Serif', fontSize)
        fontMetrics = QFontMetrics(font)

        # draw background
        background = self.data.get('background_color')
        paint.fillRect(0, 0, rulerLength, traceLengthLimit, background)

        # draw the lines
        paint.setPen(self.data.get('lines_color'))
        paint.setFont(font)

        # the builtin range() doesn't support floats
        def float_range(current, end, rangeStep):
            while current < end:
                yield current
                current += rangeStep

            # we skip 0 and start in the first step, since there's no point in drawing the first line/text (it would appear cut off, since we're at the limit)

        for a in float_range(step, limit, step):

            position = a * proportion

            if (a % 100) == 0:
                lineLength = large

                if units == 'px':
                    text = '{}{}'.format(str(a), units)
                else:
                    text = '{}{}'.format(str(int(a / 100)), units)

                textWidth = fontMetrics.boundingRect(text).width()

                paint.drawText(position - textWidth / 2,
                               traceLengthLimit / 2 + fontSize / 2, text)

            elif (a % 50) == 0:
                lineLength = large

                # since 'cm' has a different step compared to the other units
                if units == 'cm':
                    lineLength = medium

            elif (a % 25) == 0:
                lineLength = medium

            else:
                lineLength = small

            paint.drawLine(position, 0, position, lineLength)
            paint.drawLine(position, traceLengthLimit, position,
                           traceLengthLimit - lineLength)

        # paint the division lines

        if self.data.get('division_lines'):
            paint.setPen(self.data.get('divisions_color'))
            halfPoint = rulerLength / 2
            quarterPoint = rulerLength / 4
            threeQuarterPoint = 3 / 4 * rulerLength

            paint.drawLine(quarterPoint, 0, quarterPoint, traceLengthLimit)
            paint.drawLine(halfPoint, 0, halfPoint, traceLengthLimit)
            paint.drawLine(threeQuarterPoint, 0, threeQuarterPoint,
                           traceLengthLimit)

        paint.restore()
        paint.end()
Exemplo n.º 15
0
    def paintEvent(self, ev):
        p = QPainter(self)
        p.setFont(self.font)
        #p.fillRect(self.rect(), QBrush(Qt.blue))

        length = len(self.display_data)

        # Reduce to the number of lines that are available in the data
        num_rows = length // self.bytes_per_line
        if length % self.bytes_per_line > 0:
            num_rows += 1

        for l in range(num_rows):
            p.setPen(self.label_color)
            # Draw address label
            # self.instance.get_local_label(self.start_offset + l * self.bytes_per_line)
            position_string = self.display_labels[l]
            p.drawText(QPoint(self.label_offset_x, (l + 1) * self.line_height),
                       position_string)

            for i in range(
                    0,
                    min(self.bytes_per_line,
                        length - self.bytes_per_line * l)):

                #virtual_address = self.start_offset + l*self.bytes_per_line + i

                p.setPen(self.byte_color)

                current_byte = self.display_data[i + l * self.bytes_per_line]
                if current_byte.background is not None:
                    p.setBackground(current_byte.background)
                    p.setBackgroundMode(Qt.OpaqueMode)

                p.drawText(
                    QPoint(self.label_length + i * self.byte_width,
                           (l + 1) * self.line_height), current_byte.text)
                p.setBackgroundMode(Qt.TransparentMode)

                # Draw selection rects
                if current_byte.is_selected:
                    p.setPen(self.selection_color)
                    p.drawRect(
                        # TODO make these offsets configurable/dependent on font?
                        self.label_length + i * self.byte_width - 3,
                        (l) * self.line_height + 3,
                        self.byte_width,
                        self.line_height)

                # Draw annotation underlines
                if len(current_byte.annotations) > 0:
                    y_offset = 0
                    for annotation in current_byte.annotations:
                        self.annotation_pen.setColor(annotation.color)
                        p.setPen(self.annotation_pen)
                        x = self.label_length + i * self.byte_width
                        y = (l + 1) * self.line_height + y_offset + 2
                        p.drawLine(x, y, x + self.byte_width, y)
                        y_offset += 2

                # Draw constraint pipes
                if len(current_byte.constraints) > 0:
                    enabled = False
                    for constraint in current_byte.constraints:
                        if constraint.enabled:
                            enabled = True
                            break
                    if enabled:
                        p.setPen(self.enabled_constraint_pen)
                    else:
                        p.setPen(self.disabled_constraint_pen)
                    x = self.label_length + i * self.byte_width - 2
                    y = (l) * self.line_height + 3
                    p.drawLine(x, y, x, y + self.line_height)
Exemplo n.º 16
0
    def paintEvent(self, pe) -> None:
        if not self.inhibit_paint:

            extent = 1.5 * np.pi
            offset = 1.25 * np.pi

            painter = QPainter(self)

            # So that we can use the background color
            painter.setBackgroundMode(Qt.OpaqueMode)

            # Smooth out the circle
            painter.setRenderHint(QPainter.Antialiasing)

            # Use background color
            bgColor = painter.background().color()
            painter.setBrush(painter.background())
            if self._text not in implementedKnobs:
                painter.setBrush(QtGui.QBrush(QtGui.QColor(int("0xcccccc",
                                                               0))))

            # Store color from stylesheet, pen will be overridden
            pointColor = QColor(painter.pen().color())

            # print(QDial.width(self), QDial.height(self))

            # draw widget borders
            pen = QPen(QColor(self._ringColor), 1)
            pen.setCapStyle(Qt.SquareCap)
            painter.setPen(pen)
            # uncomment the following line to draw outer rect
            # painter.drawRect(0, 0, np.floor(QDial.width(self)), QDial.height(self))

            # No border
            painter.setPen(QPen(Qt.NoPen))

            # the heignt of the widget is 2*radius + 2*fontsize1 + 2*fontsize2
            # where fontsize1 = .4radius and fontsize2 = .9*.4*radius
            # so QDial.height = radius * (2+.4*2+.4*.9*2)
            #

            fontsize1factor = .4
            fontsize2reduction = .9
            fontsize2factor = fontsize1factor * fontsize2reduction

            center_x = QDial.width(self) / 2.0
            center_y = QDial.height(self) / 2.0

            if not self._hasFixedSize:
                if not self._hasFixedFontSize:
                    radius = np.min(
                        (QDial.width(self) / 2. - self._knobMargin,
                         QDial.height(self) /
                         (2. + 2 * fontsize1factor + 2 * fontsize2factor) -
                         self._knobMargin))
                    radius = np.max((radius, 1))
                    # print("Radius = ", radius, ", height = ", QDial.height(self), ", width = ", QDial.width(self))
                    center_y = center_y - radius * (fontsize1factor +
                                                    fontsize2factor)
                else:
                    radius = np.min(
                        (QDial.width(self) / 2. - self._knobMargin,
                         (QDial.height(self) - 4 * self._fixedFontSize) / 2. -
                         self._knobMargin))
                    radius = np.max((radius, 1))
                    center_y = center_y - (self._fixedFontSize *
                                           (1 + fontsize2reduction))
            else:
                radius = self._fixedSize / 2.
                radius = np.max((radius, 1))
                center_y = center_y - radius * (fontsize1factor +
                                                fontsize2factor)

            self.radius = radius

            # Draw arc
            rectangle = QtCore.QRectF(center_x - radius, center_y - radius,
                                      2 * radius, 2 * radius)
            """The startAngle and spanAngle must be specified in 1/16th of a degree, 
			i.e. a full circle equals 5760 (16 * 360). 
			Positive values for the angles mean counter-clockwise 
			while negative values mean the clockwise direction. 
			Zero degrees is at the 3 o'clock position."""

            linewidth = radius / 30. * 2

            # linewidth = 1
            pen = QPen(QColor(self._ringColor), linewidth)
            pen.setCapStyle(Qt.RoundCap)
            # pen.setCapStyle(Qt.FlatCap)

            painter.setPen(pen)

            # adapt to linewidth to make it more pleasant to the eye
            capRadius = linewidth / 4
            angleCap = np.arcsin(capRadius / radius)

            start_deg = (90 - np.rad2deg(extent / 2)) + np.rad2deg(angleCap)
            start_16deg = start_deg * 16

            extent_deg = np.rad2deg(extent) - 2 * np.rad2deg(angleCap)
            extent_16deg = extent_deg * 16

            painter.drawArc(rectangle, start_16deg, extent_16deg)

            #draw inner circle
            pen = QPen(QColor(pointColor), linewidth)
            pen.setCapStyle(Qt.RoundCap)

            painter.setPen(pen)
            painter.setBrush(QtGui.QColor(bgColor))

            radius_inner = 15. / 20. * radius
            painter.drawEllipse(QtCore.QPointF(center_x, center_y),
                                radius_inner, radius_inner)

            self.center = QtCore.QPointF(center_x, center_y)
            """
			# Get ratio between current value and maximum to calculate angle
			if (param != NULL):
				if (param->value != this->value()) 
					param->setValue(this->value())
			"""
            ratio = (QDial.value(self) - QDial.minimum(self)) / (
                QDial.maximum(self) - QDial.minimum(self))

            # The maximum amount of degrees is 270, offset by 225
            angle = ratio * extent - offset

            # Draw the indicator
            painter.setBrush(QBrush(pointColor))

            a_y = center_y + np.sin(angle) * (radius - .1)
            a_x = center_x + np.cos(angle) * (radius - .1)

            pen = QPen(pointColor, linewidth)
            pen.setCapStyle(Qt.RoundCap)
            painter.setPen(pen)

            painter.drawLine(a_x, a_y, np.round(center_x), center_y)

            if not self._hasFixedFontSize:
                fontsize1 = radius * fontsize1factor
                if self.sizeType == 1 and fontsize1 != Knob.fontsize1:
                    Knob.fontsize1 = fontsize1
                else:
                    fontsize1 = Knob.fontsize1
                fontsize2 = fontsize1 * fontsize2reduction
            else:
                fontsize1 = self._fixedFontSize
                fontsize2 = fontsize1 * fontsize2reduction

            self.fontsize1 = fontsize1

            textRect_ = QtCore.QRectF(0, center_y + radius, QDial.width(self),
                                      2 * fontsize1)

            if self.coloredTitle:
                painter.setPen(QColor(int(titleColor, 0)))

            f = painter.font()
            f.setPointSizeF(fontsize1)
            painter.setFont(f)
            # painter.drawRect(textRect_)
            painter.drawText(textRect_, Qt.AlignHCenter | Qt.AlignTop,
                             self._text)
            # painter.drawText(textRect_, Qt.AlignHCenter | Qt.AlignTop, str(fontsize1))

            textRect_ = QtCore.QRectF(0, center_y + radius + fontsize1 * 2,
                                      QDial.width(self), 2 * fontsize2)

            if self.hasFocus():
                painter.setPen(QtGui.QColor("red"))

            f.setPointSizeF(fontsize2)
            painter.setFont(f)
            # painter.drawRect(textRect_)
            painter.drawText(textRect_, Qt.AlignHCenter | Qt.AlignTop,
                             str(QDial.value(self)))

            painter.end()