Skip to content

Commit

Permalink
Use default bar style if custom style isn't found
Browse files Browse the repository at this point in the history
We save only the index of the style (0 for default)
If the number of custom styles change, it would cause
a crash.
  • Loading branch information
Yutsuten committed Dec 3, 2024
1 parent d7a8903 commit 4f172fe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,14 @@ def _update_bar_color(self) -> None:
return

self._current_bar_color = bar_color
if options['customStyle']:
available_styles = ['default', *self._qt.QStyleFactory.keys()]
custom_style = available_styles[options['customStyle']]
available_styles = self._qt.QStyleFactory.keys()

qstyle = self._qt.QStyleFactory.create(custom_style)
if options['customStyle'] and options['customStyle'] <= len(available_styles):
qstyle = self._qt.QStyleFactory.create(available_styles[options['customStyle'] - 1])
self._qprogressbar.setStyle(qstyle)

palette = self._qt.QPalette()
fg_color = self._qt.QColor(bar_color)
palette.setColor(self._qt.QPalette.ColorRole.Highlight, fg_color)
palette.setColor(self._qt.QPalette.ColorRole.Highlight, self._qt.QColor(bar_color))

if 'bgColor' in options:
bg_color = self._qt.QColor(options['bgColor'])
Expand Down
2 changes: 1 addition & 1 deletion src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def generate_form() -> Any:
tab.spin_box('borderRadiusInput', 'Border radius', [0, 20],
'Add a rounded border to the life bar.')
tab.combo_box('styleList', 'Style', ['Default', *aqt.QStyleFactory.keys()], '''Style of \
the life bar.''')
the life bar. Custom styles coloring may only work after a restart.''')
tab.color_select('fgColor', 'Bar color (default)',
"Color of the life bar's foreground.")
tab.spin_box('thresholdWarn', 'Warn threshold (%)', [0, 99],
Expand Down

0 comments on commit 4f172fe

Please sign in to comment.