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?