Skip to content

Conversation

@maxsitt
Copy link

@maxsitt maxsitt commented Oct 4, 2025

This pull request adds font customization for the LogViewer and ensures consistent monospace font usage across platforms when running the viewer.py test script.

Font customization and consistency:

  • Added a _font attribute and new methods (set_font, _apply_font) to the LogViewer class in logger.py. The font is applied via a CSS stylesheet to ensure consistent appearance.
  • Modified the clear and refresh methods in logger.py to reapply the font after clearing and to avoid double-counting log records during refresh.

Platform-aware monospace font selection:

  • Added the get_monospace_font function in tests/viewer.py to select the best available monospace font for the current operating system, improving log readability and consistency.
  • Updated the main function in tests/viewer.py to use the new font selection helper and apply the chosen font to the log viewer at startup.

Add support for setting a custom font and font size in the LogViewer widget via set_font and _apply_font methods. Ensure that the font is applied when clearing or refreshing the log view. Use `count=False` when adding records through the `refresh()` function to prevent double-counting during re-rendering.
Add `get_monospace_font()` function to select an appropriate monospace font based on the operating system. Set the custom log font and font size for the viewer.
@beatreichenbach
Copy link
Owner

Hi Max,
Thank you so much for your continued efforts!
I am going to be pretty busy in the next couple of weeks. A couple quick thoughts:
It looks like you are forcing some fonts that you picked per OS but I think it's very common for the desktop to provide a font that is used when a monospace font is requested. That's the whole purpose behind the QFont.StyleHint. I don't want to force any of those stylistic decisions on the user.
Secondly as you might have noticed, none of my packages use style sheets, they often interfere with other applications. So, I don't think stylesheets should be used.
I'll take a closer look a bit later.

@maxsitt
Copy link
Author

maxsitt commented Oct 6, 2025

Hi Beat,

thanks for your quick reply !

The added get_monospace_font() function in 5844101 was just meant as an example and can be removed again, maybe the example to set a custom font could be added as comment or just part of the documentation in the README to not force it on the user.

The current code that uses QFont.StyleHint to get an available monospace font in lines 135-137 doesn't seem to function as expected, even if changing the StyleHint, the same default font is always used (as seen in your screenshot). This is probably caused by the HTML rendering engine using its own default font and ignoring what was set for the QtWidgets.QPlainTextEdit().

I actually tested different approaches, but setting the stylesheet on the QTextDocument instance was the only one that worked out. Also, self.text_edit.document().setDefaultStyleSheet only affects HTML rendering within that specific document without affecting the widget's stylesheet and potentially leaking to other parts of the application.

That said, I'm new to a lot of stuff involved here and might definitely miss some things that you are more aware of. Please let me know what you think about my suggested approach and if you see any alternative approaches that could make more sense to set the log font manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants