我正在嘗試使用 Qt Creator 和 Qt for Python 為新應(yīng)用程序創(chuàng)建快速原型。但是,向?qū)傻拇a對我來說沒有多大意義。這是main.pyQt Creator 生成的文件:# This Python file uses the following encoding: utf-8import sysimport osfrom PySide2.QtWidgets import QApplication, QMainWindowfrom PySide2.QtCore import QFilefrom PySide2.QtUiTools import QUiLoaderclass MyMainWindow(QMainWindow): def __init__(self): super(MyMainWindow, self).__init__() self.load_ui() def load_ui(self): loader = QUiLoader() path = os.path.join(os.path.dirname(__file__), "form.ui") ui_file = QFile(path) ui_file.open(QFile.ReadOnly) loader.load(ui_file, self) ui_file.close()if __name__ == "__main__": app = QApplication([]) widget = MyMainWindow() widget.show() sys.exit(app.exec_())這是一個簡單的form.ui,只有一個按鈕:<?xml version="1.0" encoding="UTF-8"?><ui version="4.0"> <class>MyMainWindow</class> <widget class="QMainWindow" name="MyMainWindow"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>800</width> <height>600</height> </rect> </property> <property name="windowTitle"> <string>MyMainWindow</string> </property> <widget class="QWidget" name="centralwidget"> <layout class="QVBoxLayout" name="verticalLayout"> <item> <widget class="QPushButton" name="pushButton"> <property name="text"> <string>PushButton</string> </property> </widget> </item> </layout> </widget> <widget class="QMenuBar" name="menubar"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>800</width> <height>22</height> </rect> </property> </widget> <widget class="QStatusBar" name="statusbar"/> </widget> <resources/> <connections/></ui>我只是不明白類load_ui內(nèi)函數(shù)的用途MyMainWindow。我知道 PyQt5 可以.ui在使用該模塊的小部件初始化期間加載文件uic。據(jù)我所知,這對于 Python 的 Qt 來說是不可能的。我錯過了什么嗎?我正在使用 Qt Creator 4.13。
添加回答
舉報
0/150
提交
取消