Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problem with QtFormLayout



  • 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:
    1.PNG

    But evey time I remove the first line it stays like this:
    2.PNG

    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:
    3.PNG

    Ps: Im using Python 3.8.2 and PyQt5 5.13.2

    Thanks for your attention!


  • Lifetime Qt Champion

    Hi,

    Please don't post the same question in multiple sub forums.

    Duplicate

    Closing this one


Log in to reply