def add_to_font_db(cls, font_key): font_id = QFontDatabase.addApplicationFont( Resource.icon_paths[font_key]) cls.font_storage[font_key] = font_id LOGGER.debug('Font loaded and added to db: %s', QFontDatabase.applicationFontFamilies(font_id)) return QFont(QFontDatabase.applicationFontFamilies(font_id)[0], 8)
def __init__(self, page_width, page_height, crop_margin_width=0 * mm): self.page_width = page_width self.page_height = page_height self.margin_width = crop_margin_width self.include_crop_marks = bool(crop_margin_width) QApplication(['my-q-application']) f = QFontDatabase.addApplicationFont( '../../fonts/OldStandard-Regular.ttf') f = QFontDatabase.addApplicationFont('OldStandard-Italic.ttf') f = QFontDatabase.addApplicationFont('OldStandard-Bold.ttf') f = QFontDatabase.addApplicationFont('fonts/Inconsolata-Regular.ttf') f = QFontDatabase.addApplicationFont('fonts/UbuntuMono-R.ttf') f = QFontDatabase.addApplicationFont('../../fonts/GenBasB.ttf') f = QFontDatabase.addApplicationFont('../../fonts/GenBasR.ttf') #f = QFontDatabase.addApplicationFont('../../fonts/Inconsolata-Regular.ttf') # print(f) names = QFontDatabase.applicationFontFamilies(f) # print(names) self.writer = QPdfWriter('book.pdf') size = QSizeF(as_mm(2 * crop_margin_width + page_width), as_mm(2 * crop_margin_width + page_height)) print(size) self.writer.setPageSizeMM(size) margins = QMarginsF(as_mm(crop_margin_width), as_mm(crop_margin_width), as_mm(crop_margin_width), as_mm(crop_margin_width)) print(margins) self.writer.setPageMargins(margins, QPageLayout.Millimeter) self.painter = QPainter(self.writer) if self.include_crop_marks: self.draw_crop_marks()
class FontManager: """Stores various font parameters used by the app""" monospace = 'monospace' if not isinstance(TheApp, Mock): # Changes the default monospace font to one a bit less wide than Courier New font_path = pkg_resources.resource_filename( __name__, 'resources/fonts/NK57 Monospace/nk57-monospace-sc-rg.ttf') if font_path: monospace = QFontDatabase.addApplicationFont(font_path) monospace = QFontDatabase.applicationFontFamilies(monospace)[0] REAL_FONT_FACES = { FontFace.serif: 'Times New Roman', FontFace.sans: 'Helvetica', FontFace.monospace: monospace, } #: Converts the enumed font faces to actual font families that Qt will accept FONT_SCALES = { FontFace.serif: None, FontFace.sans: None, FontFace.monospace: None, } #: Stores scaling factors used to make fonts all the same width for a given font point size FONT_CACHE = {} #: Stores previously called fonts METRICS_CACHE = {} #: Stores metrics used to get font widths per font size
def get_font(cls, font_key) -> QFont(): if font_key in cls.font_storage.keys(): return QFont(QFontDatabase.applicationFontFamilies(cls.font_storage[font_key])[0], 8) if font_key in Resource.icon_paths.keys(): return cls.add_to_font_db(font_key) return QFont()
def setFontPath(cls, filename): """Set font from a font file and return it :return: QFont or False if the file is not loaded """ db = QFontDatabase() font_id = db.addApplicationFont(filename) if font_id == -1: logging.error("FIconEngine:setFontPath:: cannot load font icon.") return False cls.font = QFont(db.applicationFontFamilies(font_id)[0]) return cls.font
def setup_application_font(): try: id = QFontDatabase.addApplicationFont(GlobalFiles.MyFontPath) _fontstr = QFontDatabase.applicationFontFamilies(id)[0] _font = QFont(_fontstr, 10) app.setFont(_font) except Exception as e: warning_dialog = WarningDialog( window_title="Missing Fonts", info_message="Can't find 'OpenSans' font at " "../Resources/Fonts/OpenSans.ttf\n" + "application will use default font") warning_dialog.execute()
def __init__(self, disk_usage, node_status, node_substatus): """ Constructor """ super(TableModel, self).__init__() self._data = [] self._node_id_vs_row_number = {} self._icons = {} # Initialize icons for icon_id, icon_path in list(self._icon_paths.items()): if not icon_path: continue self._icons[icon_id] = QIcon(icon_path) # set font for arrow symbols font_id = QFontDatabase.addApplicationFont(":/fonts/symbol-signs.otf") font_family = QFontDatabase.applicationFontFamilies(font_id)[0] self._arrow_font = QFont(font_family, QFont().pointSize()+5) # Add the node itself node_ostype = get_platform() node_osname, is_server = get_os_name_and_is_server() # show "Downloading share" instead of "Syncing" if share is downlosded status = 30 if node_status == 3 and node_substatus == SUBSTATUS_SHARE \ else node_status self_info = { 'id': 'itself', 'node_ostype': node_ostype, 'node_osname': node_osname, 'node_devicetype': 'desktop', 'node_name': get_device_name(), 'is_online': node_status not in self.OFFLINE_STATUSES, 'is_itself': True, 'disk_usage': disk_usage, 'download_speed': 0., 'node_status': status, 'upload_speed': 0., } QTimer.singleShot(10, lambda: self._add_row(self_info))
def __init__(self, page_width, page_height, margin_width=0): self.page_width = page_width self.page_height = page_height self.margin_width = margin_width self.include_crop_marks = bool(margin_width) QApplication(['my-q-application']) f = QFontDatabase.addApplicationFont('OldStandard-Regular.ttf') f = QFontDatabase.addApplicationFont('OldStandard-Italic.ttf') f = QFontDatabase.addApplicationFont('OldStandard-Bold.ttf') names = QFontDatabase.applicationFontFamilies(f) print(names) self.writer = QPdfWriter('book.pdf') size = QSizeF((2 * margin_width + page_width) * mm, (2 * margin_width + page_height) * mm) self.writer.setPageSizeMM(size) margins = QMarginsF(margin_width, margin_width, margin_width, margin_width) self.writer.setPageMargins(margins) self.painter = QPainter(self.writer) if self.include_crop_marks: self.draw_crop_marks()
def load_dwarf_fortress_font() -> QFont: id_ = QFontDatabase.addApplicationFont(":/DwarfFortressVan.ttf") family = QFontDatabase.applicationFontFamilies(id_)[0] return QFont(family, 12)
class DigitalText(QWidget): def __init__(self, parent, config): super(DigitalText, self).__init__(parent) self.config = config self.value = config["min"] self.font_db = QFontDatabase() self.font_id = self.font_db.addApplicationFont("fonts/DS-DIGI.TTF") self.families = self.font_db.applicationFontFamilies(self.font_id) #print [str(f) for f in self.families] #DS-Digital self.font = QFont("DS-Digital") self.title_font = QFont("DS-Digital") self.color = QColor(config["color"]) self.red_color = QColor(config["redline_color"]) self.pen = QPen(self.color) self.red_pen = QPen(self.red_color) self.red_value = config["redline"] if self.red_value is None: self.red_value = config["max"] def sizeHint(self): return QSize(300, 75) def render(self, response): self.value = response.value.magnitude self.update() def paintEvent(self, e): painter = QPainter() painter.begin(self) #painter.setRenderHint(QPainter.Antialiasing) self.font_size = int(self.height() / 2) self.title_font_size = int(self.height() / 6) self.t_height = int(self.height() / 3) # - self.title_font_size * 2 if len(self.config["title"]) > 0: self.draw_title(painter) self.draw_value(painter) painter.end() def draw_value(self, painter): painter.save() if self.value >= self.red_value: painter.setPen(self.red_pen) else: painter.setPen(self.pen) painter.setFont(self.font) self.font.setPixelSize(self.font_size) r = QRect(0, 0, self.width(), self.t_height * 2) if self.config["numerals"]: if self.config["align"] == "right": painter.drawText(r, Qt.AlignRight | Qt.AlignBottom, "{:.2f}".format(self.value)) elif self.config["align"] == "left": painter.drawText(r, Qt.AlignLeft | Qt.AlignBottom, "{:.2f}".format(self.value)) else: painter.drawText(r, Qt.AlignCenter | Qt.AlignBottom, "{:.2f}".format(self.value)) else: if self.config["align"] == "right": painter.drawText(r, Qt.AlignRight | Qt.AlignBottom, "{:.0f}".format(self.value)) elif self.config["align"] == "left": painter.drawText(r, Qt.AlignLeft | Qt.AlignBottom, "{:.0f}".format(self.value)) else: painter.drawText(r, Qt.AlignCenter | Qt.AlignBottom, "{:.0f}".format(self.value)) #painter.drawText(r, Qt.AlignRight|Qt.AlignTop, str(self.font_size)) #painter.drawRect(r) painter.restore() def draw_title(self, painter): painter.save() painter.setFont(self.title_font) painter.setPen(self.pen) self.title_font.setPixelSize(self.title_font_size) r = QRect(0, self.t_height * 2, self.width(), self.t_height) if self.config["align"] == "right": painter.drawText(r, Qt.AlignRight | Qt.AlignTop, self.config["title"]) elif self.config["align"] == "left": painter.drawText(r, Qt.AlignLeft | Qt.AlignTop, self.config["title"]) else: painter.drawText(r, Qt.AlignCenter | Qt.AlignTop, self.config["title"]) #painter.drawText(r, Qt.AlignRight|Qt.AlignTop, str(self.title_font_size)) #painter.drawRect(r) painter.restore()
class GL_DigitalGauge(QOpenGLWidget): def __init__(self, parent, config): super(GL_DigitalGauge, self).__init__(parent) self.config = config self.value = config["min"] self.font_db = QFontDatabase() self.font_id = self.font_db.addApplicationFont("fonts/DS-DIGI.TTF") self.families = self.font_db.applicationFontFamilies(self.font_id) #print [str(f) for f in self.families] #DS-Digital self.font = QFont("DS-Digital") self.note_font = QFont("DS-Digital") self.title_font = QFont("DS-Digital") self.color = QColor(config["color"]) self.pen_color = QColor(Qt.black) self.red_color = QColor(config["redline_color"]) self.brush = QBrush(self.color) self.brush_bg = QBrush(QColor("#555555")) self.brush_red = QBrush(self.red_color) self.brush_red_bg = QBrush(self.red_color) self.pen = QPen(self.pen_color) self.red_pen = QPen(self.red_color) self.indicator_color = QColor(config["indicator_color"]) self.text_pen = QPen(self.color) self.indicator_pen = QPen(self.indicator_color) self.font.setPixelSize(self.config["font_size"]) self.pen.setWidth(1) self.red_pen.setWidth(1) # TODO: make 80 configurable s = scale(config["min"], config["max"], float(config["max"] - config["min"])/80) self.angles = map_scale(s, 0, 270) self.str_scale, self.multiplier = str_scale(s, config["scale_mult"]) self.red_angle = 270 if config["redline"] is not None: self.red_angle = map_value(config["redline"], config["min"], config["max"], 0, 270) def render(self, response): # approach the value self.value += (response.value.magnitude - self.value) / 8 self.update() def sizeHint(self): return QSize(350, 300) def paintGL(self): r = min(self.width(), self.height()) / 2 self.__text_r = r - (r/10) # radius of the text self.__tick_r = r - (r/8) # outer radius of the tick marks self.__tick_l = (r/6) # length of each tick, extending inwards self.__needle_l = (r/5) * 3 # length of the needle self.font.setPixelSize(int(max(self.width(), self.height())/3)) self.note_font.setPixelSize(int(max(self.width(), self.height())/30)) self.title_font.setPixelSize(int(max(self.width(), self.height())/12)) painter = QPainter() painter.begin(self) painter.setFont(self.font) painter.setPen(self.pen) painter.setBrush(self.brush) painter.setRenderHint(QPainter.Antialiasing) self.draw_title(painter) self.draw_value(painter) if self.config["numerals"]: self.draw_multiplier(painter) self.draw_marks(painter) painter.end() def draw_marks(self, painter): painter.save() painter.translate(self.width() / 2, self.height() / 2) # draw the ticks end = self.__tick_r - self.__tick_l yTopOffset = int(2 * self.__tick_r * math.sin(math.radians(self.angles[1] / 2)) / 2) #- 1 yBottomOffset = int(2 * end * math.sin(math.radians(self.angles[1] / 2)) / 2) #- 1 angle = map_value(self.value, self.config["min"], self.config["max"], 0, 270) angle = min(angle, 270) for a in self.angles: painter.save() painter.rotate(90 + 45 + a) if a > self.red_angle and a <= angle: painter.setBrush(self.brush_red) elif a <= angle: painter.setBrush(self.brush) elif a > self.red_angle: painter.setBrush(self.brush_red_bg) else: painter.setBrush(self.brush_bg) path = QPainterPath() path.moveTo(end, -yBottomOffset) path.lineTo(self.__tick_r, -yTopOffset) path.lineTo(self.__tick_r, yTopOffset) path.lineTo(end, yBottomOffset) path.lineTo(end, -yBottomOffset) painter.drawPath(path) painter.restore() painter.restore() def draw_title(self, painter): painter.save() painter.setPen(self.text_pen) painter.setFont(self.title_font) font_offset = int(self.height()/8) r_height = self.config["font_size"] + font_offset r = QRect(0, self.height() - r_height, self.width(), r_height) painter.drawText(r, Qt.AlignHCenter | Qt.AlignVCenter, self.config["title"]) painter.restore() def draw_value(self, painter): painter.save() painter.setPen(self.indicator_pen) painter.setFont(self.font) r_height = self.height()/2 + 20 #r = QRect(0, self.height()/2 - r_height/2, self.width(), self.height()/2 + r_height/2) r = QRect(0, 0, self.width(), self.height()) painter.drawText(r, Qt.AlignHCenter | Qt.AlignVCenter, str(int(self.value//self.multiplier))) #painter.drawText(r, Qt.AlignHCenter | Qt.AlignVCenter, "TEST") painter.restore() def draw_multiplier(self, painter): if self.multiplier > 1: painter.save() painter.setPen(self.text_pen) painter.setFont(self.note_font) s = "x" + str(self.multiplier) r = QRect(0, self.width() / 6, self.width(), self.height()) painter.drawText(r, Qt.AlignHCenter | Qt.AlignVCenter, s) painter.restore()
class DigitalBoost(QWidget): def __init__(self, parent, config): super(DigitalBoost, self).__init__(parent) self.config = config config.update({'min' : -30, 'max' : 20, 'color' : '#2e3fcc', 'redline_color' : '#ff0000', 'scale_multi': 1, 'scale_step': 10, 'redline' : 14, 'font_size' : 18, 'title' : 'Highest Trip Boost', 'x': 0, 'y': 5, 'w': 200, 'h': 200, 'numerals': 'false', 'sensor': 'Boost'}) self.value = config["min"] self.highest = config['min'] self.font_db = QFontDatabase() self.font_id = self.font_db.addApplicationFont("fonts/DS-DIGI.TTF") self.families = self.font_db.applicationFontFamilies(self.font_id) #print [str(f) for f in self.families] #DS-Digital self.font = QFont("DS-Digital") self.note_font = QFont("DS-Digital") self.title_font = QFont("DS-Digital") self.color = QColor(config["color"]) self.pen_color = QColor(Qt.black) self.red_color = QColor(config["redline_color"]) self.brush = QBrush(self.color) self.brush_bg = QBrush(QColor("#555555")) self.brush_red = QBrush(self.red_color) self.brush_red_bg = QBrush(self.red_color) self.pen = QPen(self.pen_color) self.red_pen = QPen(self.red_color) self.text_pen = QPen(self.color) self.font.setPixelSize(self.config["font_size"]) self.pen.setWidth(1) self.red_pen.setWidth(1) # TODO: make 80 configurable s = scale(config["min"], config["max"], float(config["max"] - config["min"])/80) self.angles = map_scale(s, 0, 270) self.str_scale, self.multiplier = str_scale(s, config["scale_multi"]) self.red_angle = 270 if config["redline"] is not None: self.red_angle = map_value(config["redline"], config["min"], config["max"], 0, 270) def render(self, response): # approach the value # self.value += (response.value.magnitude - self.value) / 8 # self.value += (response - self.value) / 8 self.value += (response - self.value) / 8 self.update() def sizeHint(self): return QSize(350, 300) def paintEvent(self, e): #r = min(self.width(), self.height()) / 2 #self.__text_r = r - (r/10) # radius of the text #self.__tick_r = r - (r/8) # outer radius of the tick marks #self.__tick_l = (r/6) # length of each tick, extending inwards #self.__needle_l = (r/5) * 3 # length of the needle self.font.setPixelSize(int(max(self.width(), self.height())/3)) self.note_font.setPixelSize(int(max(self.width(), self.height())/30)) self.title_font.setPixelSize(int(max(self.width(), self.height())/12)) painter = QPainter() painter.begin(self) painter.setFont(self.font) painter.setPen(self.pen) painter.setBrush(self.brush) painter.setRenderHint(QPainter.Antialiasing) self.draw_title(painter) self.draw_value(painter) #if self.config["numerals"]: # self.draw_multiplier(painter) #self.draw_marks(painter) painter.end() def draw_marks(self, painter): painter.save() '''painter.translate(self.width() / 2, self.height() / 2) # draw the ticks end = self.__tick_r - self.__tick_l yTopOffset = int(2 * self.__tick_r * math.sin(math.radians(self.angles[1] / 2)) / 2) #- 1 yBottomOffset = int(2 * end * math.sin(math.radians(self.angles[1] / 2)) / 2) #- 1 angle = map_value(self.value, self.config["min"], self.config["max"], 0, 270) angle = min(angle, 270) for a in self.angles: painter.save() painter.rotate(90 + 45 + a) if a > self.red_angle and a <= angle: painter.setBrush(self.brush_red) elif a <= angle: painter.setBrush(self.brush) elif a > self.red_angle: painter.setBrush(self.brush_red_bg) else: painter.setBrush(self.brush_bg) path = QPainterPath() path.moveTo(end, -yBottomOffset) path.lineTo(self.__tick_r, -yTopOffset) path.lineTo(self.__tick_r, yTopOffset) path.lineTo(end, yBottomOffset) path.lineTo(end, -yBottomOffset) painter.drawPath(path) painter.restore()''' painter.restore() def draw_title(self, painter): painter.save() painter.setPen(self.text_pen) painter.setFont(self.title_font) font_offset = int(self.height()/8) r_height = self.config["font_size"] + font_offset r = QRect(0, self.height() - r_height, self.width(), r_height) painter.drawText(r, Qt.AlignHCenter | Qt.AlignVCenter, self.config["title"]) painter.restore() def draw_value(self, painter): painter.save() painter.setPen(self.text_pen) painter.setFont(self.font) r_height = self.height()/2 + 20 #r = QRect(0, self.height()/2 - r_height/2, self.width(), self.height()/2 + r_height/2) r = QRect(0, 0, self.width(), self.height()) #### here for highest trip if self.value > self.highest: painter.drawText(r, Qt.AlignHCenter | Qt.AlignVCenter, f'{self.value//self.multiplier}')#str(int(self.value//self.multiplier))) self.highest = self.value #painter.drawText(r, Qt.AlignHCenter | Qt.AlignVCenter, "TEST") painter.restore() def draw_multiplier(self, painter): if self.multiplier > 1: painter.save() painter.setPen(self.text_pen) painter.setFont(self.note_font) s = "x" + str(self.multiplier) r = QRect(0, self.width() / 6, self.width(), self.height()) painter.drawText(r, Qt.AlignHCenter | Qt.AlignVCenter, s) painter.restore()
class DigitalBarHorizontal(QWidget): def __init__(self, parent, config): super(DigitalBarHorizontal, self).__init__(parent) self.config = config self.value = config["min"] self.font = QFont() self.note_font = QFont() self.color = QColor(config["color"]) self.red_color = QColor(config["redline_color"]) self.no_color = QColor() self.no_color.setAlpha(0) self.brush = QBrush(self.color) self.red_brush = QBrush(self.red_color) self.pen = QPen(self.color) self.red_pen = QPen(self.red_color) self.no_pen = QPen(self.no_color) self.font_db = QFontDatabase() self.font_id = self.font_db.addApplicationFont("fonts/DS-DIGI.TTF") self.families = self.font_db.applicationFontFamilies(self.font_id) #print [str(f) for f in self.families] #DS-Digital self.font = QFont("DS-Digital") self.note_font = QFont("DS-Digital") self.title_font = QFont("DS-Digital") self.color = QColor(config["color"]) self.pen_color = QColor(Qt.black) self.red_color = QColor(config["redline_color"]) self.brush = QBrush(self.color) self.brush_bg = QBrush(QColor("#555555")) self.brush_red = QBrush(self.red_color) self.brush_red_bg = QBrush(QColor("#73311c")) self.pen = QPen(self.pen_color) self.red_pen = QPen(self.red_color) self.text_pen = QPen(self.color) self.font.setPixelSize(self.config["font_size"]) self.note_font.setPixelSize(self.config["note_font_size"]) self.pen.setWidth(3) self.red_pen.setWidth(3) def render(self, response): # approach the value self.value += (response.value.magnitude - self.value) / 4 self.update() def sizeHint(self): return QSize(400, 60) def paintEvent(self, e): painter = QPainter() painter.begin(self) self.pre_compute(painter) painter.setFont(self.font) painter.setPen(self.text_pen) painter.setRenderHint(QPainter.Antialiasing) self.draw_title(painter) #self.draw_border(painter) self.draw_bars(painter) painter.end() def pre_compute(self, painter): w = self.width() h = self.height() s = scale(self.config["min"], self.config["max"], float(self.config["max"] - self.config["min"])/(self.config["w"]/4)) self.angles = map_scale(s, 0, self.config["w"]) self.str_scale, self.multiplier = str_scale(s, self.config["scale_mult"]) self.red_angle = self.config["w"] if self.config["redline"] is not None: self.red_angle = map_value(self.config["redline"], self.config["min"], self.config["max"], 0, self.config["w"]) # recompute new values self.l = 2 # left X value self.r = w - self.l # right X value self.t_height = self.config["font_size"] + 8 self.bar_height = max(0, h - self.t_height) - self.l self.value_offset = map_value(self.value, self.config["min"], self.config["max"], self.l, self.r) self.red_offset = w if self.config["redline"] is not None: self.red_offset = map_value(self.config["redline"], self.config["min"], self.config["max"], self.l, self.r) def draw_title(self, painter): painter.save() r = QRect(0, 0, self.width(), self.t_height) painter.drawText(r, Qt.AlignVCenter, self.config["title"]) #painter.drawText(r, Qt.AlignVCenter, "Test") painter.drawRect(r) 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() def draw_bars(self, painter): painter.save() painter.translate(0, self.t_height) painter.setPen(self.no_pen) painter.setBrush(self.brush) self.t_height = self.config["font_size"] + 8 self.bar_height = max(0, self.height() - self.t_height) - self.l #end = self.__tick_r - self.__tick_l #yTopOffset = int(2 * self.__tick_r * math.sin(math.radians(self.angles[1] / 2)) / 2) #- 1 #yBottomOffset = int(2 * end * math.sin(math.radians(self.angles[1] / 2)) / 2) #- 1 angle = map_value(self.value, self.config["min"], self.config["max"], 0, self.config["w"]) angle = min(angle, self.config["w"]) for a in self.angles: painter.save() #painter.rotate(90 + 45 + a) if a > self.red_angle and a <= angle: painter.setBrush(self.brush_red) elif a <= angle: painter.setBrush(self.brush) elif a > self.red_angle: painter.setBrush(self.brush_red_bg) else: painter.setBrush(self.brush_bg) path = QPainterPath() path.moveTo(0, 0 + a) path.lineTo(self.bar_height, 0 + a) path.lineTo(self.bar_height, 2 + a) path.lineTo(0, 2 + a) path.lineTo(0, 0 + a) painter.drawPath(path) painter.restore() painter.restore() 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()