I am using QGridLayout in Pyqt5 to build a window in python. What I want to do is that the elements are not available to occupy the entire width and height of the window, but they are grouped in the upper area of the window. My code is:
def __init__(self, fileInfo, parent=None):
super(tabBuscadorProductos, self).__init__(parent)
#Fichero de configuracion
config = configparser.ConfigParser()
config.read('properties.conf')
self.label = QtWidgets.QLabel()
self.label.setGeometry(QtCore.QRect(10, 40, 131, 16))
self.label.setObjectName("label")
self.label.setText("Criterio de busqueda:")
self.comboBox = QtWidgets.QComboBox()
self.comboBox.setGeometry(QtCore.QRect(150, 40, 121, 22))
self.comboBox.setObjectName("comboBox")
list = config.get('COMBO_CRITERIOS', 'productos').split(" ")
self.comboBox.addItems(list)
self.label_2 = QtWidgets.QLabel()
self.label_2.setGeometry(QtCore.QRect(350, 40, 121, 16))
self.label_2.setObjectName("label_2")
self.label_2.setText("Producto:")
self.lineEdit = QtWidgets.QLineEdit()
self.lineEdit.setGeometry(QtCore.QRect(470, 40, 271, 22))
self.lineEdit.setObjectName("lineEdit")
self.label_3 = QtWidgets.QLabel()
self.label_3.setGeometry(QtCore.QRect(10, 90, 55, 16))
self.label_3.setObjectName("label_3")
self.label_3.setText("Local: ")
self.comboBox_2 = QtWidgets.QComboBox()
self.comboBox_2.setGeometry(QtCore.QRect(150, 80, 121, 22))
self.comboBox_2.setObjectName("comboBox_2")
# locales = config.get('COMBO_EMPRESAS', 'empresas')
self.comboBox_2.addItems(obtenerLocales())
self.pushButton = QtWidgets.QPushButton()
self.pushButton.setGeometry(QtCore.QRect(920, 130, 93, 28))
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(os.getcwd()+"\images\lupa2.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton.setIcon(icon)
self.pushButton.setObjectName("pushButton")
self.pushButton.setText("Buscar")
self.pushButton.clicked.connect(self.buscar)
self.checkBox = QtWidgets.QCheckBox()
self.checkBox.setGeometry(QtCore.QRect(10, 130, 211, 20))
self.checkBox.setObjectName("checkBox")
self.checkBox.setText("Incluir productos con stock a 0")
mainLayout = QGridLayout()
mainLayout.addWidget(self.label, 0, 0, 1, 1)
mainLayout.addWidget(self.comboBox, 0, 1, 1, 1)
mainLayout.addWidget(self.label_2, 0, 4, 1, 1)
mainLayout.addWidget(self.lineEdit, 0, 5, 1, 1)
mainLayout.addWidget(self.label_3, 1, 0, 1, 1)
mainLayout.addWidget(self.comboBox_2, 1, 1, 1, 1)
mainLayout.addWidget(self.pushButton, 3, 5, 1, 1)
mainLayout.addWidget(self.checkBox, 3, 0, 1, 1)
mainLayout.setColumnStretch(0, 1)
mainLayout.setColumnStretch(3, 1)
mainLayout.setRowStretch(0, 1)
mainLayout.setRowStretch(3, 1)
# mainLayout.addStretch(1)
self.setLayout(mainLayout)
And what I want to get is this (the table is not yet implemented):