这是使用PyQT5作为UI的首次提交,将后端和UI合并到1个工程中,统一使用了Python,没有使用JS和HTML
This commit is contained in:
48
UI/reserved/test_qml.py
Normal file
48
UI/reserved/test_qml.py
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
简单的QML测试
|
||||
"""
|
||||
|
||||
import sys
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
from PyQt5.QtQml import QQmlApplicationEngine
|
||||
from PyQt5.QtCore import QUrl
|
||||
|
||||
# 简单的QML内容
|
||||
simple_qml = """
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15
|
||||
|
||||
ApplicationWindow {
|
||||
visible: true
|
||||
width: 640
|
||||
height: 480
|
||||
title: "测试窗口"
|
||||
|
||||
Text {
|
||||
text: "Hello, PyQt5 QML!"
|
||||
anchors.centerIn: parent
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
def main():
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
# 创建临时QML文件
|
||||
with open("test.qml", "w", encoding="utf-8") as f:
|
||||
f.write(simple_qml)
|
||||
|
||||
engine = QQmlApplicationEngine()
|
||||
engine.load(QUrl.fromLocalFile("test.qml"))
|
||||
|
||||
if not engine.rootObjects():
|
||||
print("Failed to load QML")
|
||||
sys.exit(-1)
|
||||
|
||||
sys.exit(app.exec_())
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user