pip install PySide2

2021-06-21  本文已影响0人  我的小小笔尖

1. 虚拟环境下安装 PySide2

https://pypi.org/project/PySide2/
PySide2 5.15.2, Released: Nov 20, 2020
provides access to the complete Qt 5.12+ framework.

pip install PySide2

安装成功提示:

Installing collected packages: shiboken2, PySide2
Successfully installed PySide2-5.15.2 shiboken2-5.15.2

PySide2依赖Clang,可访问下面地址安装
https://download.qt.io/development_releases/prebuilt/libclang/

2. 小例子 Qt for Python Tutorial HelloQML

更多示例:
https://wiki.qt.io/Qt_for_Python/Tutorial

view.qml

import QtQuick 2.0

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

    Rectangle {
        x:50; y:50
        width: 100
        height: 100
        color: "red"
     }

    Text {
        text: "Hello World"
        color: "#ffffff"
        font.pixelSize: 32
        anchors.centerIn: parent
    }
}

main.py

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

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

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

运行截图


捕获.JPG
上一篇下一篇

猜你喜欢

热点阅读