Search code examples
c++user-interfacewxwidgets

C++ wxWidgets: Change Font of Sizer


I recently started learning C++ and wxWidgets and now I'm building a calculator program. I have a grid sizer with buttons and I want to know is it possible to change the font of the whole sizer instead of changing the font of every single button?


Solution

  • Sizers are not windows and so don't have any font, so, no, you can't just call SetFont() on a sizer. You can iterate over all sizer items and call SetFont() on each item which is a window. Or, somewhat less efficiently (because you "waste" a window), but more conveniently, you can make all your button children of a wxPanel and associate the existing sizer with this panel. Then you'd be able to call SetFont() on the panel, which is a window, and so would propagate the font change to all of its children by default.