I was trying to change the font of some listbox items, and (after tinkering and trying stuff) figured out that if I add a widget to a panel, the font I set to the widget gets reset, or rather, gets set to the panel's font.

Is this expected behaviour?

And if so, how do I change a font of a widget that I plan to add to a panel without changing the panel's font?

I'll try changing the font AFTER I add it to the panel. See where it takes me.
EDIT: No dice. I tried getting a pointer to a button I added to a panel after I added it and changing its font, and it didn't work.
« Last Edit: 19 July 2017, 03:10:02 by desocupado »



  • *****
  • 1143
    • View Profile
    • Texus's Blog
When a widget is added to its parent, it inherits the font and Gui is the only object with a built-in font. My guess is that you are settings these fonts before the panel gets added to the gui. No matter what the font of the widget is set to, when the panel has no font yet and is added to the gui, its setFont is called to give it a font. Since the setFont function doesn't know the difference between such call and a manual call to setFont where the intention is to change the font of the children as well, all widgets inside the panel will get the new font. A workaround in your code would be to manually set the font of the panel before changing that of the children (but then it would again be overwritten when the panel is added to another panel before being added to the gui) or only set the font after the panel is added to the gui.

A solution on my side would be to give setFont an extra boolean to choose to pass the font to all child widgets, but I already made that option kinda impossible in the design of 0.8.