On Thu, 1 Apr 2021 11:12:49 +0200 d0 wrote:
d> the docs for wxNotebook suggest doing a
d> "panel.SetBackgroundColour(notebook.GetThemeBackgroundColour())" for
d> Windows. This does work just fine with native controls, but I noticed that
d> because HasTransparentBackground() is still true for the panel, inheritance
d> of the background color does not work. Custom drawn controls end up with
d> the wrong background color.
d>
d> A minimal reproducer (Python, nothing wxPython specific though):
Thanks for the example! I've transcribed it (not quite faithfully) to C++
thus:
---------------------------------- >8 --------------------------------------
diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp
index 470e765423..cdaad61626 100644
--- a/samples/minimal/minimal.cpp
+++ b/samples/minimal/minimal.cpp
@@ -26,6 +26,9 @@
#include "wx/wx.h"
#endif
+#include "wx/notebook.h"
+#include "wx/generic/stattextg.h"
+
// ----------------------------------------------------------------------------
// resources
// ----------------------------------------------------------------------------
@@ -175,6 +178,22 @@ bool MyApp::OnInit()
CreateStatusBar(2);
SetStatusText("Welcome to wxWidgets!");
#endif // wxUSE_STATUSBAR
+
+ auto nb = new wxNotebook(this, wxID_ANY);
+ auto panel = new wxPanel(nb);
+ auto sizer = new wxBoxSizer(wxVERTICAL);
+ sizer->Add(new wxStaticText(panel, wxID_ANY, "Native"), wxSizerFlags().Border());
+ sizer->Add(new wxGenericStaticText(panel, wxID_ANY, "Generic"), wxSizerFlags().Border());
+ panel->SetSizer(sizer);
+ panel->SetBackgroundColour(nb->GetThemeBackgroundColour());
+ nb->AddPage(panel, "Theme bg");
+
+ panel = new wxPanel(nb);
+ sizer = new wxBoxSizer(wxVERTICAL);
+ sizer->Add(new wxStaticText(panel, wxID_ANY, "Native"), wxSizerFlags().Border());
+ sizer->Add(new wxGenericStaticText(panel, wxID_ANY, "Generic"), wxSizerFlags().Border());
+ panel->SetSizer(sizer);
+ nb->AddPage(panel, "Default bg");
}
---------------------------------- >8 --------------------------------------
Visually, I don't see any difference under neither MSW 7 nor MSW 10 with
the default theme, but I do see the difference if I explicitly turn off the
use of themes for the executable: in this case, the first page has grey
background, while the second one has the dark grey one, which shows that
explicitly setting GetThemeBackgroundColour() is still useful (which has
surprised me, and not in a good way, as I think it should just work right
automatically out of the box and thought this was fixed a long time ago).
However the backgrounds of the generic and native labels still look the
same.
So I wonder which system and theme do you use for them to appear
differently? Or do they also appear the same to you and the problem is
just the part below?
d> print(wx.version()) # 4.1.1 msw (phoenix) wxWidgets 3.1.5
d>
d> print(nb.GetThemeBackgroundColour()) # White, as expected
d>
d> print(panel.GetBackgroundColour()) # White
d>
d> print(panel.HasTransparentBackground()) # True(!)
d>
d> print(label2.GetBackgroundColour()) # Grey
But I do see this and agree that it seems wrong. I'll try to think about
it more, but for now I'd like to understand whether we're seeing the same
thing or if you see another problem, which I don't see, for some reason.
Thanks,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/