Details
-
Bug
-
Resolution: Out of scope
-
Not Evaluated
-
None
-
6.x
-
None
Description
SVGs with nested svg elements are not handled properly. At the very least from what I can tell, PySide ignores viewBox parameters in the inner svg elements.
Because attachments are not working for some reason, here is an SVG file that is not handled properly:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="40" height="40" viewBox="0 0 100 100"><circle stroke="none" fill="#183d76" r="48%" cx="50%" cy="50%"></circle><g transform="translate(50 50) scale(0.69 0.69) rotate(0) translate(-50 -50)" style="fill:#ffffff"><svg fill="#ffffff" xmlns="http://www.w3.org/2000/svg" data-name="Layer 1" viewBox="0 0 200 200" x="0px" y="0px"><path d="M178.057,17.748H21.943A13.442,13.442,0,0,0,8.516,31.175V136.748a13.442,13.442,0,0,0,13.427,13.427H76v24.077H54.957a4,4,0,1,0,0,8h90.086a4,4,0,0,0,0-8H124V150.175h54.057a13.442,13.442,0,0,0,13.427-13.427V31.175A13.442,13.442,0,0,0,178.057,17.748ZM116,174.252H84V150.175h32Zm67.484-37.5a5.434,5.434,0,0,1-5.427,5.427H21.943a5.434,5.434,0,0,1-5.427-5.427V31.175a5.434,5.434,0,0,1,5.427-5.427H178.057a5.434,5.434,0,0,1,5.427,5.427Z"></path><path d="M170.7,34.532H29.3a4,4,0,0,0-4,4v90.859a4,4,0,0,0,4,4H170.7a4,4,0,0,0,4-4V38.532A4,4,0,0,0,170.7,34.532Zm-4,90.859H33.3V42.532H166.7Z"></path></svg></g></svg>
Set the name of the file to 'Computer.svg' (no quotes) and run this:
#!/usr/bin/env python3 from PySide6 import QtWidgets, QtGui, QtSvg import sys app = QtWidgets.QApplication(sys.argv) renderer = QtSvg.QSvgRenderer("./Computer.svg") image = QtGui.QImage(40, 40, QtGui.QImage.Format_ARGB32) painter = QtGui.QPainter(image) renderer.render(painter) image.save("./test123.png") sys.exit(app.exec())
You will note that the inner design appears very small, on the top left of the image, instead of displaying the same way as in the SVG, prominently in the center.
Here is an SVG that works correctly:
<svg width="40" height="40" id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 500"><defs><style>.cls-1{fill:#157ee8;}.cls-2{fill:none;stroke:#fff;stroke-linecap:round;stroke-miterlimit:10;stroke-width:16px;}</style></defs><title>phrase</title><path class="cls-1" d="M500,250A250,250,0,1,1,0,250C0,111.93,111.93,0,250,0S500,111.93,500,250Z"/><path class="cls-2" d="M183.31,363.19h84.31c23.73,0,43.14-18.11,43.14-40.24l0-12.67A10.3,10.3,0,0,1,321.1,300h13.2c23.73,0,43.14-18.11,43.14-40.24V177.06c0-22.13-19.41-40.24-43.14-40.24H165.69c-23.73,0-43.14,18.11-43.14,40.24v82.72c0,22.13,19.41,40.24,43.14,40.24h77.58"/><line class="cls-2" x1="177.56" y1="194.94" x2="322.06" y2="194.94"/><line class="cls-2" x1="179.73" y1="243.56" x2="264.17" y2="243.56"/></svg>
Please let me know if you require more information.
Edit: The attachments are no longer throwing errors. I have attached the good SVG file (Phrase.svg) and the bad SVG file (Computer.svg), as well as the code.
Edit2: Tested on PySide 6.0.0 and PySide 6.1.2.