def draw_bar(self, painter): painter.save() painter.translate(0, self.t_height) painter.setPen(self.no_pen) painter.setBrush(self.brush) if in_range(self.red_offset, self.l, self.r): if self.value_offset <= self.red_offset: painter.drawRect( QRect(self.l, 0, self.value_offset, self.bar_height)) else: painter.drawRect( QRect(self.l, 0, self.red_offset, self.bar_height)) painter.setBrush(self.red_brush) painter.setPen(self.red_pen) painter.drawRect( QRect(self.red_offset, 0, self.value_offset - self.red_offset, self.bar_height)) else: painter.drawRect( QRect(self.l, 0, self.value_offset, self.bar_height)) painter.restore()
def draw_border(self, painter): painter.save() painter.translate(0, self.t_height) if in_range(self.red_offset, self.l, self.r): # non-red zone path = QPainterPath() path.moveTo(self.red_offset, 0) path.lineTo(self.l, 0) path.lineTo(self.l, self.bar_height) path.lineTo(self.red_offset, self.bar_height) painter.drawPath(path) # red zone path = QPainterPath() path.moveTo(self.red_offset, 0) path.lineTo(self.r, 0) path.lineTo(self.r, self.bar_height) path.lineTo(self.red_offset, self.bar_height) painter.setPen(self.red_pen) painter.drawPath(path) else: painter.drawRect( QRect( self.l, self.l, self.r - self.l, self.bar_height, )) painter.restore()