I want to make each slice of a pie chart a color of my choosing. I need to know the snytax of QPieSlice (if that is what I use) and how to attach a color to a particular slice of the pie. For example, I want the "Auto" slice to be '#00FF00', the "Employment" slice to be '#1A8CFF", etc.
Below are the pieces of my pie. I have tried various things like:
QPieSlice.setBrush(QPieSlice.setColor(QColor('#00FF00')))
but it does not work, and even if it did, I do not know how to attach it to a particular slice and where to put it.
series.append("Auto", self.expensesWindow.piechart[0])
series.append("Employment", self.expensesWindow.piechart[1])
series.append("Insurance", self.expensesWindow.piechart[2])
series.append("Household", self.expensesWindow.piechart[3])
series.append("Housing", self.expensesWindow.piechart[4])
series.append("Entertainment", self.expensesWindow.piechart[5])
series.append("Utilities", self.expensesWindow.piechart[6])
series.append("Other", self.expensesWindow.piechart[7])
When you use the
append()method ofQPieSeries, passing it the name and value it returns its associatedQPieSliceso you must use that elementBut you can also build a
QPieSliceusing the name and value you can pass it using the other append() method:And you can also build by creating a list of
QPieSliceusing the thirdappend()method:Update:
In your case, use the second method: