Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with QtFormLayout
Forum Updated to NodeBB v4.3 + New Features

Problem with QtFormLayout

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 186 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • FurquimF Offline
    FurquimF Offline
    Furquim
    wrote on last edited by Furquim
    #1

    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!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Duplicate

      Closing this one

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved