I'm making a database editor using PySide6. I made a QPushButton to add 2 rows in a QFormLayout. See screenshot 1
Looks good right? That is what it looked like before you click "Add another column". But then I click and instead of making 2 more rows, it moves them to the end See screenshot 2
Here is my code:
def addTableForm(self):
def addColumnForm():
layout.addRow(columnNameLabel, columnName)
layout.addRow(columnTypeLabel, columnType)
layout = QFormLayout(self)
widget = QWidget(self)
tableNameLabel = QLabel(parent=self, text="Enter the table name")
tableName = QLineEdit(parent=self)
columnNameLabel = QLabel(parent=self, text="Add a column")
columnName = QLineEdit(parent=self)
columnTypeLabel = QLabel(parent=self, text="Enter the type of the column")
columnType = QLineEdit(parent=self)
moreColumnsLabel = QLabel(parent=self, text="Add another column")
moreColumns = QPushButton(parent=self, text="Add another column", clicked=addColumnForm)
moreColumns.setFixedWidth(200)
cancel = QPushButton(self, text="Cancel", clicked=self.selectTables)
confirm = QPushButton(self, text="Confirm")
layout.addRow(tableNameLabel, tableName)
addColumnForm()
layout.addRow(moreColumnsLabel, moreColumns)
layout.addRow(cancel, confirm)
widget.setLayout(layout)
self.setCentralWidget(widget)
The function is inside a MainWindow class, heir to QMainWindow. Can you please help me out? By the way, can you please also give me some styling tips? I don't like the way how all the widgets are crammed together.
Thanks