def paintEvent(self, event):
painter = QPainter(self)
if len(self.m_histogram) == 0:
painter.fillRect(0, 0, self.width(), self.height(),
QColor.fromRgb(0, 0, 0))
return
barWidth = self.width() / float(len(self.m_histogram))
for i, value in enumerate(self.m_histogram):
h = value * self.height()
# Draw the level.
painter.fillRect(barWidth * i, self.height() - h,
barWidth * (i + 1), self.height(), Qt.red)
# Clear the rest of the control.
painter.fillRect(barWidth * i, 0, barWidth * (i + 1),
self.height() - h, Qt.black)
评论列表
文章目录