I'm trying to create a GUI for a chess game. I'm using the grid layout and when the main window opens, the labels I have are in the correct size. However, when I resize the window, the grid layout does move along with the window but its contents are out of alignment and the row and column sizes don't match anymore. Is there a way of making it so the cell sizes in the grid layout will always be a square (so row size = column size).
Correct Scale where rowsize = columnsize :

Incorrect Scales example where rowsize is not equal to columnsize :

class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.setGeometry(500,150,860,860)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
#Adding Grid Layout to the main widget
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName("gridLayout")
self.gridLayout.setHorizontalSpacing(0)
self.gridLayout.setVerticalSpacing(0)
all_position_labels = []
colour = False
for x in range(8):
row = []
for y in range(8):
#Creating the labels
self.position = QtWidgets.QLabel(self.centralwidget)
self.position.setText("Place " + str(x) + " " + str(y))
if colour == True:
self.position.setStyleSheet("border: 0.1em solid black; background: gray;")
colour = False
else:
self.position.setStyleSheet("border: 0.1em solid black;")
colour = True
#Adding labels to the GridLayout
self.gridLayout.addWidget(self.position, x, y, 1, 1)
row.append(self.position)
all_position_labels.append(row)
if colour == True:
colour = False
else:
colour = True
del row
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 20))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Thanks.