I am currently programming a chess game for a school project. To create the Human-Machine Interface, I am using PyQt5.
In order to draw the chessboard, I've built the following function :
def drawRectangles(self, qp):
taille = self.case
for i in range(8):
for j in range(1, 9):
s = i + j
c = s % 2
qp.setBrush(QtGui.QColor(c * 250, c * 250, c * 250))
qp.drawRect(100 + i * taille, j * taille, taille, taille)
However, when I click on a chess piece on the chessboard, I wish to paint in a different color (let's say in red) the area where said chess piece can move. In order to do so, I've built the following function :
def reachable_cells(self, cells):
size = self.size
qp = QtGui.QPainter()
qp.begin(self)
qp.setBrush(QtGui.QColor(0, 0, 150))
for i in range(len(cells)):
cell = cells[i]
qp.drawRect(100 + cell[0] * size, cell[1] * size, size, size)
However, this doesn't have any effect on my chessboard, and the cells which are reachable for a given chesspiece remain black or white.
Would anyone have some tips on how to solve that problem ?
In the event where it isn't possible to do something like that, is it possible to overlay a reachable chess cell with a circle picture ?
Thanks for any help !