The calls to painter.begin()
and painter.end()
are redundant, as these are both done automatically when the painter is created and deleted. Re-calling painter.begin()
on an active painter is technically an error, which is why you are seeing those warnings.
If you simply remove the redundant lines, the error messages should go away.
PS:
An alternate way to fix the issue would be to omit passing self
to the constructor of the painter. This would leave the painter uninitialized, so the call to painter.begin(self)
would then be necessary to make it active.
So, in summary, you should do either:
painter = QtGui.QStylePainter()
painter.begin(self)
...
or just:
painter = QtGui.QStylePainter(self)
...