best size is not updated after SetFont() with GTK >= 3.6
|Reported by:||pcor||Owned by:|
GTK+ 3.6 introduced caching of widget styling information. This cache is only updated at particular times of GTK's choosing. AFAICT there is no way to get the cache to be updated at any other time. So after setting a font with a non-default size, GetBestSize() will recalculate (and cache) a size which is still based on the old font. This breaks the common wxWidgets practice of doing layout and sizing during window initialization. Here is a simple example using the minimal sample:
--- samples/minimal/minimal.cpp (revision 76148) +++ samples/minimal/minimal.cpp (working copy) @@ -172,6 +172,22 @@ CreateStatusBar(2); SetStatusText("Welcome to wxWidgets!"); #endif // wxUSE_STATUSBAR + + wxString msg = wxS("The quick brown fox jumps over the lazy dog. The slow brown fox strolls around it."); + wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); + + wxStaticText* original = new wxStaticText(this, wxID_ANY, msg); + sizer->Add(original); + + wxStaticText* large = new wxStaticText(this, wxID_ANY, msg); + wxFont font = large->GetFont(); + font.SetPointSize(font.GetPointSize() * 3); + large->SetFont(font); + sizer->Add(large); + + SetSizer(sizer); + sizer->Layout(); + sizer->Fit(this); }
There appears to be no way to fix this. The best we can do is invalidate the best size when we know the GTK+ style information has been updated. This would allow user code to work around the problem, for example by re-doing the layout and sizing from a wxShowEvent handler.