I am running code on a Windows 7 VM with Qt Creator and I am getting a module "material" is not installed
error when running my code. It is initialized with Python 3.8 using Pyside6. My Qt Creator is version 4.15.0
This is the QML code:
import QtQuick 2.0
import QtQuick.Controls 2.12
Item {
width: 640
height: 480
visible: true
Rectangle {
id: rectangle
x: 232
y: 220
width: 200
height: 200
color: "#c96565"
}
}
This is the Python script: It is a modified version of one of the example default scripts.
import os
import sys
import urllib.request
import json
from pathlib import Path
import PySide6.QtQml
from PySide6.QtQuick import QQuickView
from PySide6.QtCore import QStringListModel, Qt, QUrl
from PySide6.QtGui import QGuiApplication
if __name__ == '__main__':
#Set up the application window
app = QGuiApplication(sys.argv)
view = QQuickView()
view.setResizeMode(QQuickView.SizeRootObjectToView)
#Load the QML file
qml_file = Path(__file__).parent / "main.qml"
view.setSource(QUrl.fromLocalFile(os.fspath(qml_file.resolve())))
#Show the window
if view.status() == QQuickView.Error:
sys.exit(-1)
view.show()
#execute and cleanup
app.exec()
del view
I didn't use Qt Quick Control elements in the QMl yet though. Even if I do have a Quick Control elements there the same thing happens. However, if I remove/comment out the import statement for Qt Quick Controls below, the application runs fine. I've tried changing the version number next to quick controls too without success.
UPDATE: It seems that not being able to find the module is a path issue, so I brute forced the path into the qml file by adding this line to the top: import "./Controls.2" as QtQuickControls
And I copied pasted the Controls.2 folder that is nested in the PySide6 folder into the root directory of this project. The error I get now is
The plugin <filepath to qtquickcontrols2plugin.dll> uses incompatible Qt library. <5.15.0> [release] import "./Controls.2" as QtQuickControls
I figured it out: I don't need to brute force the path in; in the .pydevproject file of your python project, make sure you add in the full path to PySide6 because for some reason the system cannot find it without the path. Something like this:
<pydev_pathproperty name="org.python.pydev.PROJECT_EXTERNAL_SOURCE_PATH">
<path>\path\to\your\python\venv\or\folder\Lib\site-packages\PySide6</path>
</pydev_pathproperty>
If that doesn't work, try calling the Material
module directly:
import QtQuick.Controls.Material 2.12