以正确的方式设置表单布局。 QGridLayout.addLayout(QLayout,int,int,Qt.Alignment alignment = 0):参数不够

时间:2014-10-24 16:22:21

标签: python user-interface layout pyqt qgridlayout

我正在尝试为用户信息数据制作表单:

#!/usr/bin/python
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys, os, time

class SetName(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        self.show()
        toplayout = QGridLayout()
        self.setWindowTitle('Personal Info')
        self.form_layout = QFormLayout()
        self.setLayout(self.form_layout)
        self.line_edit_param = QLineEdit(self)

        self.line_edit_param.setPlaceholderText("Write Here")
        self.form_layout.addRow('Write Name', self.line_edit_param)      
        toplayout.addLayout(self.form_layout)
        self.setFocus()

class LearnApp(QDialog):
    def __init__(self):
        super(QDialog, self).__init__()
        self.setWindowTitle("LearnApp")

        self.active = False

        close_button = QPushButton("Close")
        close_button.clicked.connect(self.close)

        self.check_button = QPushButton("Check")
        self.check_button.clicked.connect(self.set_data)        
        self.tr = QTextEdit()
        self.tr.setReadOnly(True)
        # layout
        layout = QHBoxLayout()        
        #layout.addWidget(self.button3)
        sub_layout = QVBoxLayout()
        sub_layout.addWidget(self.check_button)
        sub_layout.addWidget(close_button)
        layout.addLayout(sub_layout)
        layout.addWidget(self.tr)
        self.setLayout(layout)
        self.setFocus()

    def set_data(self):
        print "in set_data"
        SetName()

app = QApplication(sys.argv)
dialog = LearnApp()
dialog.show()
app.exec_()

它以我想要的方式打开表单,但它给了我以下错误:

Traceback (most recent call last):
  File "data_log.py", line 50, in set_data
    SetName()
  File "data_log.py", line 20, in __init__
    toplayout.addLayout(self.form_layout)
TypeError: arguments did not match any overloaded call:
  QGridLayout.addLayout(QLayout, int, int, Qt.Alignment alignment=0): not enough arguments
  QGridLayout.addLayout(QLayout, int, int, int, int, Qt.Alignment alignment=0): not enough arguments

我到底哪里出错了?我应该怎么解决这个问题? 我试图调试很多,但无法意识到我正在做的错误。

0 个答案:

没有答案