randrew/phantomstyle

Loss of dark theme in menus

Closed this issue · 5 comments

I am using your application, Ripcord. This seems to be more of an issue with phantomstyle though, so filing here. I have yet to figure out exactly how to intentionally reproduce this, but it seems to happen after resuming from hibernation. I will update if I do figure it out how to easily reproduce it. Using Windows 10 x64 build 17763.

As for the actual issue: QMenus and the top QMenuBar on Ripcord loose their dark theme and turn white (Fusion theme coloring), while the rest of the application stays dark. A restart fixes this. Illustration of the areas that turn white (will update with actual white version when it happens again)

image

This is actually a bug in Qt. It occurs due to certain Windows events triggering a reset of the application palette via the QPA mechanism. All Qt programs on Windows are susceptible to this, regardless of which QStyle they are using. It's existed for years and is unlikely to be fixed anytime soon. You can see reports of this happening as far back as 5 years ago https://forum.qt.io/topic/43104/solved-possible-bug-in-qapplication-setpalette-what-to-do and various bugs in the Qt bug tracker being opened/closed over time related to it.

I should add, for what it's worth -- if you're able to trigger this reliably, please post how you're able to do it, so that another bug/case for this can be opened on the Qt bug tracker.

Thanks! It has happened again when I wasn't looking, I'll see if I can catch the cause

For anyone who finds this in the future - you need to filter out these 5 Windows messages and never let Qt see them:

WM_STYLECHANGED
WM_STYLECHANGING
WM_PALETTECHANGED
WM_THEMECHANGED
WM_SYSCOLORCHANGE

If any of them get through (especially WM_THEMECHANGED and WM_SYSCOLORCHANGE) there's a chance Qt will puke and break the palettes on some widgets (like QMenuBar.)

Easiest way is to make a QAbstractNativeEventFilter subclass and install it on your QApplication.

There's a chance this has been fixed in later versions of Qt -- I'm still on 5.9

And these appears to happen because neither this code https://code.woboq.org/qt5/qtbase/src/plugins/platforms/windows/qwindowscontext.cpp.html#1283 nor this code https://code.woboq.org/qt5/qtbase/src/plugins/platforms/windows/qwindowstheme.cpp.html#_ZN13QWindowsTheme19windowsThemeChangedEP7QWindow check to see if they should scribble over the state of the current QStyle/application or not -- if you have Windows platform theme at all, it will wreck you.