Search code examples
pythonqtpysideqtquick2pyside6

How use Material Style in pyside?


I have pyside6 application,I want to set the style of application to Material Design so I set sys.argv += ['--style', 'material'] in below:

import sys,os
from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine, qmlRegisterType
from PySide6.QtCore import QObject, Slot, Signal, QTimer, QUrl
import PySide6

if __name__ == "__main__":
    #os.environ['QT_QUICK_CONTROLS_STYLE'] = "material"
    #==================================================
    sys.argv += ['--style', 'material']
    #==================================================
    app = QGuiApplication(sys.argv)
    engine = QQmlApplicationEngine()
    engine.load(os.path.join(os.path.dirname(__file__), "qml/main.qml"))
    if not engine.rootObjects():
        sys.exit(-1)
    sys.exit(app.exec_())

But I giving the error:

QQmlApplicationEngine failed to load component
file:///D:/QtProjects/qtforpythonprojects/JooyaTrader01/qml/main.qml: module "material" is not installed

I recently install Qt 6 and I use pyside6


Solution

  • It seems that in Qt6 the names are more restrictive than Qt5 in the names so you should use "Material" instead of "material".