我需要帮助。我在 QT Designer 中添加了两个按钮,然后我使用了水平布局。Ctrl + R - 一切看起来都很好。
然后我将表单转换为 Python:
pyuic4.bat Form2.ui > Form2.py
并运行应用程序。布局似乎不起作用。所有按钮都被覆盖。
表单的 py 代码(我没有更改任何内容):
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(383, 222)
self.horizontalLayout = QtGui.QHBoxLayout(Form)
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.pushButton = QtGui.QPushButton(Form)
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.horizontalLayout.addWidget(self.pushButton)
self.pushButton_2 = QtGui.QPushButton(Form)
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.horizontalLayout.addWidget(self.pushButton_2)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Form", None))
self.pushButton.setText(_translate("Form", "PushButton 1", None))
self.pushButton_2.setText(_translate("Form", "PushButton 2", None))
以及应用程序的代码:
import sys
from PyQt4 import QtCore, QtGui
from Form2 import Ui_Form
class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Form()
self.ui.setupUi(self)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())
我将不胜感激任何帮助。再见,沃伊泰克