Re-styling The Tree And Body On-The-Fly

25 views
Skip to first unread message

Thomas Passin

unread,
Aug 13, 2024, 10:06:02 AM8/13/24
to leo-editor
Simple scripts can re-style the tree and body editor, over-riding the current theme's settings.  These changes only last until the outline is loaded again, but they can be very helpful when your want to tweak a theme.

Say you want to try a different font size for the tree.  Normally you would need to load up the theme's outline, edit it, and restart Leo.  That's awkward, slow, and you can't really compare before and after.

These scripts let you change any of Qt's CSS properties, not just font size.  Want to see what the tree would look like using Times New Roman? No Problem.  Italics? Sure.  First, the tree:

gui = g.app.gui
tw = gui.find_widget_by_name(c, 'treeWidget')
# Change font of both label and headline editor
style = '* {font-size: 9.5pt;}'
tw.setStyleSheet(style)


Note that you can use half-point sizes, as shown here. The particular properties specified here will change, leaving the others set by the theme untouched. You can change the property value and run the script again right away.

Here's the equivalent for the body editor:

gui = g.app.gui
body_editor = gui.find_widget_by_name(c,'richTextEdit')
style = '* {font-size: 9.5pt;}'
body_editor.setStyleSheet(style)


For the font family, the CSS style is

style = '* {font-family: 'Times New Roman";}'

If you know your CSS, you can change any CSS properties supported by Qt. We use the universal selector ("*") so we don't need to figure out the exact object name to use, which can sometimes be a problem.  These styles will only affect the object you are styling and its children. It won't affect any other objects.

Reply all
Reply to author
Forward
0 new messages