Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

qss url() not working on Python 3.9



  • Hey,
    just to make sure it's not me: the following code runs properly with both PySid2 and PySide6 on Python3.8 on my machine (Windows 10), i.e. when checking the checkbox I can see the indicator from the svg

    from PySide6.QtCore import QDir
    from PySide6.QtWidgets import QApplication, QMainWindow, QCheckBox
    import sys
    import os
    
    
    class MainWindow(QMainWindow):
        def __init__(self):
            super().__init__()
            self.setCentralWidget(QCheckBox('test'))
    
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
    
        # the icon used below lies in the same dir as this file
        QDir.addSearchPath('icon', os.path.abspath(os.path.dirname(__file__)))
    
        app.setStyleSheet("""
    QCheckBox::indicator:checked {
        image: url(icon:/checkbox_checked.svg);
    }
        """)
        mw = MainWindow()
        mw.show()
        sys.exit(app.exec_())
    

    When I run it on Python3.9, there's no indicator, the whole thing just disappears. This applies to all qss url()s and both PySide2 and PySide6. Is this a bug?
    Thanks!

    Versions for both Python 3.8 and 3.9:

    • PySide2 5.15.2
    • PySide6 6.0.1

    edit also doesnt work with absolute paths, also not with strings in the url() which all seems to work on Python 3.8


  • Lifetime Qt Champion

    Hi,

    Did you try the same path without the leading slash with Python 3.9 ?



  • @SGaist Hi, yes same result


  • Lifetime Qt Champion

    Ok, can you also give the exact versions of Python ?
    And how did you install PySide ? Pip or conda ?



  • jep, Python 3.8.7 and 3.9.3 and installation via pip



  • Quizás ese widget no acepta ese estilo



  • @nutrx It works for me, share the log when executing the script using the following command: QT_DEBUG_PLUGINS=1 python /path/of/your_script.py. If you use .png instead of .svg, do you still have that problem?



  • @eyllanesc png works in both versions. with svg, using

    set QT_DEBUG_PLUGINS=1
    python3.9 my_file.py
    

    when checking the box it fails with "Cannot load library [...]\\Roaming\\Python\\Python39\\site-packages\\PySide6\\plugins\\imageformats\\qsvg.dll: Das angegebene Modul wurde nicht gefunden. [cannot find the module]" besides other similar errors (even though it exists). When I run it with Python3.8 it works.

    However, I noticed that PySide2/6 (and weirdly I think also the Python 3.9 installation) was located in Roaming for Python 3.9 and that it seems to look in various places for packages and the paths for site-packages in Roaming differ from the paths in AppData/Local/Programs. Therefore, although there was only one global (PATH) Python 3.9 installed, I tried by removing the Roaming stuff and reinstalled Python 3.9 and the packages, and now it seems to work...


Log in to reply