Your First QtQuick/QML Application

https://doc.qt.io/qtforpython/tutorials/basictutorial/qml.html
https://doc.qt.io/qtforpython/overviews/qml-tutorial1.html?highlight=rectangle
https://doc.qt.io/qt-5/qtquick-qmlmodule.html

1.进入Python虚拟环境

虚拟环境已安装PySide6

2.创建 view.qml

使用QML语言描述界面

iimport QtQuick 2.0

Rectangle {
    width: 320; height: 480
    color: "green"

    Rectangle {
        x: 50; y:20
        width: 30; height: 40
        color: "red"
    }

    Text {
        text: "Hello World"
        anchors.centerIn: parent
    }
}

3.创建 view.py

使用Python加载QML文件

from PySide6.QtWidgets import QApplication
from PySide6.QtQuick import QQuickView
from PySide6.QtCore import QUrl

app = QApplication([])
view = QQuickView()
url = QUrl("view.qml")

view.setSource(url)
view.show()
app.exec()

4.运行程序

python view.py

界面截图


6152.PNG

你可能感兴趣的:(Your First QtQuick/QML Application)