I am trying to render styled pygal charts using Qt SVG renderer. But I still problems with background colors because it is black. Shouldn't it be controlled by the style of pygal chart? It should look like the first chart in http://www.pygal.org/en/stable/documentation/builtin_styles.html#darkstyle
import sys
import pygal
from PySide import QtGui, QtSvg
class Chart(QtGui.QWidget):
def __init__(self, parent=None):
super(Chart, self).__init__(parent)
chart = pygal.StackedLine(fill=True, interpolate='cubic',
style=pygal.style.DefaultStyle)
# or e.g. DarkSolarizedStyle
chart.add('A', [1, 3, 5, 16, 13, 3, 7])
chart.add('B', [5, 2, 3, 2, 5, 7, 17])
chart.add('C', [6, 10, 9, 7, 3, 1, 0])
chart.add('D', [2, 3, 5, 9, 12, 9, 5])
chart.add('E', [7, 4, 2, 1, 2, 10, 0])
svgSource = chart.render()
self.renderer = QtSvg.QSvgRenderer()
self.renderer.load(svgSource)
def paintEvent(self, event):
if self.renderer is not None:
painter = QtGui.QPainter(self)
self.renderer.render(painter)
return True
return super(Chart, self).paintEvent(event)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
window = Chart()
window.show()
result = app.exec_()
sys.exit(result)
UPDATE: I get the same issue when using PyQt5, PyQt4, Pyside and also when using directly QSvgWidget. My suspicion is that it does not work because of failure in loading CSS files referenced in the SVG. Or it might be some limited scope of SVG specification which is supported by Qt as mentioned in Does QT support svg?.