Chris Ray
Chris Ray

Reputation: 303

import Qt5Compat.GraphicalEffects: QML module not found

I am on Arch Linux and I am trying to use PySide6 and QT6 in my project since I will need to be able to use singleton qml objects and PySide2 doesn't seem to support the registration of singleton qml objects. My project uses ColorOverlays and DropShadows, so I will need GraphicalEffects support. However, according to the doc pages, these aren't supported by Qt6 and require a compatibility module, Qt5Compat.GraphicalEffects to be supported.

I am trying to import Qt5Compat.GraphicalEffects into my QML code via the import statement below:

import Qt5Compat.GraphicalEffects

However, when I add this to my project's QML in QT Creator, I am getting the error: "QML module not found."

Here are some things I have tried in order to remedy this issue:

How can I fix this issue with importing Qt5Compat.GraphicalEffects?

EDIT:

I am using Python and PySide6 for my backend code, but I am writing the front-end in QML, which is where I am having my issue.

Upvotes: 1

Views: 4910

Answers (4)

Alberto Salvia Novella
Alberto Salvia Novella

Reputation: 1250

On Qt6 declare the different items as not visible, then show them through an MultiEffect.

import QtQuick 2.15
import QtQuick.Effects 6.6
import org.kde.kirigami 2.20 as Kirigami

Item {
    property string avatarPath
    property real faceSize: Kirigami.Units.gridUnit * 7

    Rectangle {
        id: mask
        anchors.centerIn: parent
        color: "#b3b3b3"
        width: faceSize
        height: faceSize
        radius: 180
        visible: false
    }

    Image {
        id: face
        source: wrapper.avatarPath
        sourceSize: Qt.size(faceSize, faceSize)
        visible: false
    }

    MultiEffect {
        id: maskedFace
        source: face
        anchors.fill: face
        maskEnabled: true
        maskSource: ShaderEffectSource {
            sourceItem: mask
        }
    }
    
    Rectangle {
        id: border
        anchors.centerIn: parent
        color: "transparent"
        border.color: "#ececec"
        border.width: 3
        width: faceSize + 4
        height: faceSize + 4
        radius: 180
    }
}

Upvotes: 0

iiMouad
iiMouad

Reputation: 35

I found the source of that issue in Pyside6.6.1 , Pyside6 does come with Qt5Compat Module, the problem is that it could not be found in the path that is used by QtCreator in my case was: C:\Qt\6.6.1\mingw_64\qml and I look up in that link and there is no Qt5Compat , BUT, I Found it here :

<your_project_name>\venv\Lib\site-packages\PySide6\qml
    ├── Qt
    ├── Qt3D
    ├── Qt5Compat
    │   └── GraphicalEffects // found it !!
    ...

so what I did was copy that into C:\Qt\6.6.1\mingw_64\qml , and the problem was fixed for me

Upvotes: 0

Rafa
Rafa

Reputation: 31

Here could be the solution for the problem.

From the main directory "QT" you need to take the Qt5Compad module. This must be added to the development environment.

It works with Pyside6 and PyQT6.

Here is a better description: QT6.4 QML PYTHON module "Qt5Compat.GraphicalEffects" is not installed

Upvotes: 2

eyllanesc
eyllanesc

Reputation: 244132

You have to keep in mind that PySide2 is a binding of Qt5 and PySide6 is that of Qt6.

If you want to use ColorOverlay or DropShadow with then you should follow the Qt5 documentation that says you should use import QtGraphicalEffects 1.15.

If instead you want to use it in it has moved those components to the Qt5Compat module so you should use: import Qt5Compat.GraphicalEffects.

So the way to import will depend on whether you are using PySide2 (Qt5) or PySide6 (Qt6).

Note: QtCreator does not have many capabilities so many times it will throw false positives since it is not able to understand PySide. Unfortunately they have not given it "much affection" so it is not optimized to work with python obtaining that type of warnings. So just obviate the warning.

Upvotes: 1

Related Questions