tags: python qt pyside6 ![]{cs}(BarChartWidget_01a.png) ```py from icecream import ic; ic.configureOutput(includeContext=True) import PySide6.QtCore import PySide6.QtGui import PySide6.QtWidgets import PySide6.QtNetwork app = PySide6.QtWidgets.QApplication() import random class BarChartWidget(PySide6.QtWidgets.QWidget): def __init__(self,*xs,**kw): super().__init__(*xs,**kw) self.values = [ random.random() for x in range(8) ] self.color = PySide6.QtGui.QColor("red") def __setitem__(self,idx,val): val = min(1.0,max(0.0,float(val))) idx = int(idx) % 8 self.values[idx] = val self.update() def __getitem__(self,idx): idx = int(idx) % 8 return self.values[idx] def keyPressEvent(self,e): print("key") for i in range(8): x = random.random() self[i] = x def paintEvent(self,e): with PySide6.QtGui.QPainter(self) as p: rect = self.rect() width = rect.width() height = self.height() nvalues = len(self.values) colwidth = width / nvalues p.fillRect(rect,PySide6.QtCore.Qt.black) for i,val in enumerate(self.values): x = i*colwidth print(i,x,val) p.fillRect(x,height*val,colwidth,height - height*val,self.color) if __name__ == "__main__": w = BarChartWidget() w.show() app.exec() ```