How to use svg file as QPushButton icon? (QT for python)

Viewed 45

I am using QT designer to make a user interface. I have a QPushButton on which I would like to display the icon "leaf-scan-gray.svg". I can load in the file in the property editor, and it shows up on the button in the preview. But when I convert my .ui file to a .py file (pyside6-uic ui_scantab.ui > ui_scantab.py in command line) and run my application, the image simply does not appear. If I use a png file instead, it works fine.

Here is the generated code relevant to the PushButton:

    self.pushButton = QPushButton(Form)
    self.pushButton.setObjectName(u"pushButton")
    self.pushButton.setEnabled(False)
    self.pushButton.setMinimumSize(QSize(225, 60))
    self.pushButton.setMaximumSize(QSize(150, 16777215))
    self.pushButton.setLayoutDirection(Qt.LeftToRight)
    icon = QIcon()
    icon.addFile(u"assets/leaf-scan-gray.svg", QSize(), QIcon.Normal, QIcon.Off)
    self.pushButton.setIcon(icon)
    self.pushButton.setIconSize(QSize(32, 32))

The file is located in the project directory, in a subfolder called "assets"

I'm also using a style.qss file to add some styling to the button and some other objects, but this doesn't seen to have an effect on the issue since it persists if I remove all of the contents of the qss file.

I'm really at a loss as to what's gone wrong here because I was actually able to display this same svg file on this same button yesterday.

Edit: I solved this issue by reinstalling python and pycharm

0 Answers
Related