0

I'm trying to make a form for user info data:

#!/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_()

It opens up the form the way I wanted it but it's giving me following error:

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

Where exactly I'm going wrong? How should I tackle this? I tried to debug a lot but couldn't realize the mistake I'm doing.

tryPy
  • 71
  • 1
  • 11
  • Did you read the error message? It tells you *exactly* what the problem is, so there's no need to debug any further. The [QGridLayout.addLayout](https://qt-project.org/doc/qt-4.8/qgridlayout.html#addLayout) functions have either four or six arguments, with only the last being optional. You only provided **one** argument - hence, "not enough arguments", as the message says. – ekhumoro Oct 24 '14 at 16:57
  • I am confused as to what layout you are trying to get. You set the layout of your widget to self.form_layout (a QFormlayout). But then you try to add that self.form_layout to toplayout (a QGridLayout). Are you perhaps meaning to add toplayout into self.form_layout instead? – Becca codes Oct 24 '14 at 17:04
  • @ekhumoro so what should be my arguments in this case?? I am not getting it. – tryPy Oct 24 '14 at 18:06
  • @Becca adding self.form_layout to toplayout is wrong?? I replicated the same thing I did in LearnApp where I'm doing layout.addLayout(sub_layout) – tryPy Oct 24 '14 at 18:07
  • @tryPy. I provided a link to the relevant Qt docs. – ekhumoro Oct 24 '14 at 18:18
  • In LearnApp, you set self's layout to layout, and then you set layout's layout to sub_layout. (self > layout > sub_layout). In set name, you set self's layout to self.form_layout, and you also set toplayout's layout to self.form_layout. (self > self.form_layout; toplayout > self.form_layout)... My guess is that you are meaning to do (self > self.form_layout > toplayout) or (self > toplayout > self.form_layout). But that is jsut a guess. – Becca codes Oct 24 '14 at 19:43

0 Answers0