pyqt有两类,第一类就是Qt Widgets;另一类则是Qt Quick,对手持设备或者触摸设备做了优化;传统的图像和动画则更加适配的。
Qt Quick使用了QML这个编程的语言
Qt, QML, Widgets…What Is The Difference? - Qt for Python
examples/src/06 QML Python example at _ · pyqt/examples (github.com)
QtWidgets
是包括了内置好的组件,主要是按钮、标签、盒子以及菜单栏等内容,使用Widget开发的界面,目标是不影响用户的体验,也能自行修改相关的组件属性,像颜色这些的。
QML是可替代的方案,也可以用来create用户的界面,和Widgets相比较的话, 是在phone应用开发的时应运而生的,和Qt Quick模块配合使用,能够在手持设备端支持拖拉拽、动画等操作,QML/Quick内的应用多是动态的应用,QML更多用在手持设备,但桌面端也能使用
main.qml
import QtQuick 2.2
import QtQuick.Window 2.2
Window {
Image {
id: background
source: "background.png"
}
Image {
id: wheel
anchors.centerIn: parent
source: "pinwheel.png"
Behavior on rotation {
NumberAnimation {
duration: 250
}
}
}
MouseArea {
anchors.fill: parent
onPressed: {
wheel.rotation += 90
}
}
visible: true
width: background.width
height: background.height
}
main.py
from PyQt6.QtQml import QQmlApplicationEngine
from PyQt6.QtWidgets import QApplication
app = QApplication([])
engine = QQmlApplicationEngine()
engine.load(r"C:\Users\10696\Desktop\access\examples-_\src\06 QML Python example\main.qml")
app.exec()