Search code examples
pythonqtqmlqt-creatorv-play

How to convert a qml file from V-Play into python?


I have a qml file, it looks like the below (created by V-Play):

import VPlayApps 1.0
import QtQuick 2.0

App {
    // You get free licenseKeys from https://v-play.net/licenseKey
    // With a licenseKey you can:
    //  * Publish your games & apps for the app stores
    //  * Remove the V-Play Splash Screen or set a custom one (available with the Pro Licenses)
    //  * Add plugins to monetize, analyze & improve your apps (available with the Pro Licenses)
    //licenseKey: "<generate one from https://v-play.net/licenseKey>"

    NavigationStack {

        Page {
            title: qsTr("My page")

        }

        AppTextField {
            id: appTextField
            x: 0
            y: 329
            width: 256
            height: 19
            anchors.centerIn: parent
        }

        AppTextField {
            id: appTextField1
            x: 0
            y: 329
            width: 256
            height: 19
            anchors.verticalCenterOffset: 50
            anchors.centerIn: parent
        }

        Text {
            id: text1
            x: 0
            y: 620
            width: 24
            height: 20
            text: qsTr("A")
            font.pixelSize: 25
            anchors.horizontalCenter: appTextField1.horizontalCenter
        }

        AppButton {
            id: button
            x: 0
            y: 575
            width: 24
            height: 20
            text: qsTr("Click me please!")
            anchors.horizontalCenter: appTextField1.horizontalCenter
        }
    }
}

I created many PyQt5 apps, by Qt Designer, so it would be a .ui file which I could convert easily into a python file by pyuic5, but this is now the first time I used V-Play Qt Creator.

So now my question is:

How do I convert this into a python file (.py), as you see in the code I created two input areas (AppTextField), I would like it to become a python file so I can add the function which adds up the numbers in the input areas, I tried some stuff, but none of them worked, I viewed this one, Developing Python applications in Qt Creator, and some more, but they don't achieve my goal.

How would I go about doing that?


Solution

  • QML is interpreted by Qt to generate graphics items. I don't think you can convert QML into Python.

    But, you can easily integrate this file into a python script : http://pyqt.sourceforge.net/Docs/PyQt5/qml.html

    app = QGuiApplication(sys.argv)
    engine = QQmlApplicationEngine()
    engine.load(QUrl('./main.qml'))
    app.exec_()