Search code examples
widgetgeometrypyqt4grid-layout

PyQt - QGridLayout without changing Qwidget Geometry?


I'm working with PyQt and I was wondering if there is any way to set a grid layout in a window so that, for example, one button's geometry wouldn't be affected by the configuration of the layout - because I'm trying to have my button in a square shape and, with the grid layout, it always becomes a long rectangle.

Also, I have multiple rows and columns, and to edit each minimum size would be horrifying. So, is there is any way to establish the geometry of a widget in a grid layout?

UPDATE: my grid

    self.Grid = QtGui.QGridLayout()
    self.Grid.addWidget(self.Button1,0,0)
    self.Grid.addWidget(self.Box1,2,1)
    self.Grid.addWidget(self.Box2,2,3)
    self.Grid.addWidget(self.Button2,0,4,Qt.AlignRight)
    self.Grid.setRowMinimumHeight(1,50)
    self.Grid.setRowMinimumHeight(1,50)
    self.Grid.setRowMinimumHeight(3,250)
    self.Grid.setColumnMinimumWidth(0,100)
    self.Grid.setColumnMinimumWidth(2,50)
    self.Grid.setColumnMinimumWidth(4,100)
    self.setLayout(self.Grid)

Solution

  • Given the example code in your question, just add something like the following:

        self.Button1.setMinimumSize(50, 50)
        self.Button1.setMaximumSize(50, 50)
    

    or:

        self.Button1.setFixedSize(50, 50)