Problem with QtFormLayout
Locked
Unsolved
General and Desktop
-
Hello, guys!
I'm new to PyQt5 and I have a basic question that I couldn't solve. I use pyqt designer to organize the layout and widgets.
Im trying to make a form like this:
But evey time I remove the first line it stays like this:
I don't why this is happening. The first row ("TextLabel") I made using the designer and only changed the MaximumWidth and MinimumWidth for the label text and the LineEdit.
I did the same thing in the code. I only modified the MaximumWidth and MinimumWidth for each component in the row.
Here is my code
def main(): variable_names=["test1","test2"] self.create_form(variable_names) self.clear_layout(self.formLayout_output) self.create_form(variable_names) def create_form(self, variable_names: list): self.lineEdit_out_objs = [QLineEdit() for i in range( (len(variable_names) ) )] self.label_out_objs = [QLineEdit() for i in range( (len(variable_names) ) )] print(self.label_outTemplate.minimumWidth()) for i in range(len(variable_names)): self.formLayout_output.addRow(variable_names[i], self.lineEdit_out_objs[i]) #config Labels proprieties here: self.label_out_objs[i].setMinimumWidth(self.label_outTemplate.minimumWidth()) self.label_out_objs[i].setMaximumWidth(self.label_outTemplate.maximumWidth()) #config LineEdit proprieties here: self.lineEdit_out_objs[i].setMinimumWidth(self.lineEdit_outTemplate.minimumWidth()) self.lineEdit_out_objs[i].setMaximumWidth(self.lineEdit_outTemplate.maximumWidth()) def clear_layout(self, layout): for i in reversed(range(layout.count())): widgetToRemove = layout.itemAt(i).widget() # remove it from the layout list layout.removeWidget(widgetToRemove) # remove it from the gui widgetToRemove.setParent(None)
And here is the layout configuration in Qt Desginer:
Ps: Im using Python 3.8.2 and PyQt5 5.13.2
Thanks for your attention!