PySide2 QQmlApplicationEngine No Window



  • Hi,
    I am trying to run below code inside Maya, it runs without any error but still engine window is not visible. Tell me what's wrong or missing in code ??

    ball. py

    from PySide2.QtCore import QObject, QUrl, Slot
    from PySide2.QtQml import QQmlApplicationEngine
    from PySide2.QtQuick import QQuickWindow
    import maya.cmds as mc
    
    class Ball(QObject):
        def __init__(self):
            QObject.__init__(self)
    
        @Slot(int) 
        def add(self, arg1):
            mc.polySphere(r=arg1)
            
    engine = QQmlApplicationEngine()
    ball = Ball()
    engine.rootContext().setContextProperty("ball", ball)
    engine.load("E:/code/ball.qml")
    

    ball.qml

    import QtQuick 2.3
    import QtQuick.Controls 1.2
    
    ApplicationWindow {
        id: itemID
        visible: true
        width:480
        height:320
        color: "whitesmoke"
    
        Slider {
            id: radiusSliderID
            x: 214
            y: 141
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.verticalCenter: parent.verticalCenter
            stepSize: 1
            maximumValue: 20
            minimumValue: 1
            value: 1
        }
    
        Text {
            id: radiusValueID
            x: 218
            y: 194
            text: radiusSliderID.value
            font.bold: true
            anchors.horizontalCenter: parent.horizontalCenter
            font.pixelSize: 30
        }
    
        Button {
            id: sphereBtnID
            x: 208
            y: 262
            width: 80
            height: 30
            text: qsTr("Create Sphere")
            anchors.horizontalCenter: parent.horizontalCenter
            onClicked: {
                ball.add(radiusSliderID.value)
            }
        }
    
    }
    
    


  • Have you doublechecked how things should be run inside Maya?

    I suggest you try running the code as a standalone Python QT app first. For that, your code will need to also instantiate a QApplication object and then run the _exec method on it. That may actually be the reason why you're seeing nothing...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.