解決する
私は変更しました:
self.ui = base_class()
の中へ:
self.ui = form_class()
self.ui.setupUi(self)
そして今、それは機能します!
その場で.uiファイルを使用できるように、いくつかのコードを機能させようとしています。このように、Python コードを実行すると、Qt Designer による更新がすぐに使用されます。
スニペットをいじって使用した後、次のコードになりました。しかし、何とか .ui のボタンが表示されません。誰でもアイデアはありますか?
import sys,os
from PyQt4 import QtCore, QtGui, uic
form_class, base_class = uic.loadUiType('try_ui.ui')
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent = None):
QtGui.QWidget.__init__(self, parent)
self.ui = base_class()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MainWindow()
myapp.show()
sys.exit(app.exec_())
そして try_ui.ui シンプルなボタン:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>323</width>
<height>111</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>120</x>
<y>30</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>323</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>