class QS(QtWidgets.QGraphicsScene):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
self.lines = []
self.draw_grid()
self.set_opacity(0.3)

def draw_grid(self):
    width = Settings.NUM_BLOCKS_X * Settings.WIDTH
height = Settings.NUM_BLOCKS_Y * Settings.HEIGHT
self.setSceneRect(0, 0, width, height)
self.setItemIndexMethod(QtWidgets.QGraphicsScene.NoIndex)
pen = QPen(QColor(255, 0, 100), 1, Qt.SolidLine)
for x in range(0, Settings.NUM_BLOCKS_X + 1):
    xc = x * Settings.WIDTH
self.lines.append(self.addLine(xc, 0, xc, height, pen))
for y in range(0, Settings.NUM_BLOCKS_Y + 1):
    yc = y * Settings.HEIGHT
self.lines.append(self.addLine(0, yc, width, yc, pen))

def set_visible(self, visible=True):
    for line in self.lines:
        line.setVisible(visible)

def delete_grid(self):
    for line in self.lines:
        self.removeItem(line)
del self.lines[:]

def set_opacity(self, opacity):
    for line in self.lines:
        line.setOpacity(opacity)
How to draw a proper grid on PyQt?