PySide2(5.6.0~a1) Qt UI 文件加载器返回一个空窗口,而 PyQt5 加载器工作正常。你能向我解释我错在哪里吗?
非工作 PySide2 版本:
import sys
from PySide2.QtWidgets import QDialog, QApplication
from PySide2 import QtUiTools
class AppWindow(QDialog):
def __init__(self):
super().__init__()
self.ui = QtUiTools.QUiLoader().load("dialog1.ui")
self.show()
app = QApplication(sys.argv)
w = AppWindow()
sys.exit(app.exec_())
工作 PyQt5 版本:
import sys
from PyQt5.QtWidgets import QDialog, QApplication
from PyQt5 import uic
class AppWindow(QDialog):
def __init__(self):
super().__init__()
self.ui = uic.loadUi("dialog1.ui", self)
self.show()
app = QApplication(sys.argv)
w = AppWindow()
sys.exit(app.exec_())
使用此功能也不起作用:
def loadUiWidget(uifilename, parent=None):
loader = QtUiTools.QUiLoader()
uifile = QtCore.QFile(uifilename)
uifile.open(QtCore.QFile.ReadOnly)
ui = loader.load(uifile, parent)
uifile.close()
return ui