I would like to render SVG files with PyQt5.
The simplest way to do that is to use QSvgGenerator applied on a QPainter object.
However, for some reason I have to render text in the output SVG file. To do that, having a QApplication running is compulsory because some components initialized during the execution of QApplication are needed. Otherwise, QPainter.drawText()
methods end in a SEGFAULT.
I'm now able to generate text in my SVG file by creating a QSvgWidget object with handles the painting through the paintEvent
method.
If I just run the application with the exec_
method, everything works fine. However I'm only interested in generating the SVG, so I don't want to be forced to close the main window with my mouse (I'd like to run my program on a headless server). Here is my base code:
app = QApplication(sys.argv)
drawer = MyDrawerClass()
drawer.show()
app.exec_()
and MyDrawerClass
inheritates from QSvgWidget
and implements printEvent
method which is successfully called when executing the app.
So my question is: Is there a way to run the app a headless way and quit it after everything is rendered? I read a few things on QTimer
but I can't find any example which suits my usage.