Fix SetFont for rich wxTextCtrl when in dark mode (PR #25856)

13 views
Skip to first unread message

tmodes-dev

unread,
Oct 3, 2025, 10:12:52 AM (3 days ago) Oct 3
to wx-...@googlegroups.com, Subscribed

Calling wxTextCtrl::SetFont' on a wxTextCtrl with wxTE_RICH2 style results in black text on dark background when in dark mode.
This affects also the function wxShowTip. This can be seen in unmodified dialogs sample (Show tip of the day CTRL+T).
The PR fixes this by copying the default style into the modified style with the new font.

  • wxWidgets version 3.3.2
  • wxWidgets port wxMSW
  • OS Windows 11 24h2 Build 26100.6584

You can view, comment on, or merge this pull request online at:

  https://github.com/wxWidgets/wxWidgets/pull/25856

Commit Summary

  • 1cd95b8 Fix SetFont for rich wxTextCtrl when in dark mode

File Changes

(1 file)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/25856@github.com>

VZ

unread,
Oct 5, 2025, 4:26:16 PM (13 hours ago) Oct 5
to wx-...@googlegroups.com, Subscribed
vadz left a comment (wxWidgets/wxWidgets#25856)

Thanks, this looks correct but it potentially changes the behaviour when other attributes are set and I'm not sure if we want this. I don't have time to think about that right now, so what about applying this:

diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp
index 96225f19f8..3ffacce605 100644
--- a/src/msw/textctrl.cpp
+++ b/src/msw/textctrl.cpp
@@ -3131,6 +3131,15 @@ bool wxTextCtrl::SetFont(const wxFont& font)
         // the default font for it.
         wxTextAttr attr;
         attr.SetFont(font);
+
+        // In dark mode we also need to set the colours explicitly, just as we
+        // do for the colours of the control itself in Create().
+        if ( wxMSWDarkMode::IsActive() )
+        {
+            attr.SetTextColour(GetForegroundColour());
+            attr.SetBackgroundColour(GetBackgroundColour());
+        }
+
         SetStyle(-1, -1, attr);
     }
 

instead? AFAICS it also solves the problem and doesn't raise any new questions.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/25856/c3369305998@github.com>

Reply all
Reply to author
Forward
0 new messages