w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
drawPie() with customized borders

Assuming your custom Pie is a subclassed QGraphicsRectItem, you could try something like this:

class CustomPie(QtGui.QGraphicsRectItem):

    angle = 2000

    def paint(self, painter, option, widget):

        # Create the path to draw the lines
        path = QtGui.QPainterPath()
        path.moveTo(self.rect().width()/2, self.rect().height()/2)
        path.lineTo(self.rect().width(), self.rect().height()/2)
        path.arcMoveTo(self.rect(), self.angle/16)  # arcMoveTo in degrees
        path.lineTo(self.rect().width()/2, self.rect().height()/2)

        # draw a pie with no Pen
        painter.setPen(QtGui.QPen(QtCore.Qt.NoPen))
        painter.setBrush(QtGui.QBrush(QtCore.Qt.lightGray))
        painter.drawPie(self.rect(), 0, self.angle)

        # Draw the path with a custom Pen
        painter.setPen(QtGui.QPen(QtCore.Qt.black, 2))
        painter.drawPath(path)

Here we override paint to draw a Pie and a path (actually quite similar to your own method). You would have to override __init__ as well (angle as a class attribute is probably not what you want) but that's the idea.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.