Skip to content

Add dark mode checker depending on Qt version #3507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2025

Conversation

ann0see
Copy link
Member

@ann0see ann0see commented Jun 30, 2025

Short description of changes
Solves darkmode color issue in mixer dialog:
Connected:
Server label in dark mode Windows connected
Disconnected:
Server label in dark mode Windows disconnected

CHANGELOG: SKIP

Context: Fixes an issue?

Fixes: #3395

Does this change need documentation? What needs to be documented and how?

No

Status of this Pull Request

Ready for review. Working

What is missing until this pull request can be merged?
Review

Checklist

  • I've verified that this Pull Request follows the general code principles
  • I tested my code and it does what I want
  • My code follows the style guide
  • I waited some time after this Pull Request was opened and all GitHub checks completed without errors.
  • I've filled all the content above

@ann0see ann0see marked this pull request as draft June 30, 2025 18:20
@ann0see ann0see added this to Tracking Jun 30, 2025
@github-project-automation github-project-automation bot moved this to Triage in Tracking Jun 30, 2025
@ann0see ann0see moved this from Triage to Waiting externally in Tracking Jun 30, 2025
@ann0see ann0see added this to the Release 3.12.0 milestone Jun 30, 2025
@ann0see
Copy link
Member Author

ann0see commented Jun 30, 2025

macOS legacy and non legacy seem to work as expected.

@ann0see
Copy link
Member Author

ann0see commented Jun 30, 2025

Windows seems to work now too.

@ann0see ann0see force-pushed the bug/windowsDarkMode branch 5 times, most recently from b53079e to f70841f Compare June 30, 2025 19:02
@ann0see
Copy link
Member Author

ann0see commented Jun 30, 2025

Light mode might have a slightly wrong color for the line surrounding the mixer board:

border.

But I suppose this is non blocking. Otherwise, I think this is good as is.

@ann0see ann0see moved this from Waiting externally to Waiting on Team in Tracking Jun 30, 2025
@ann0see ann0see marked this pull request as ready for review June 30, 2025 19:37
@ann0see ann0see requested review from softins and pljones June 30, 2025 19:37
@ann0see ann0see added bug Something isn't working Windows Windows runtime issue labels Jun 30, 2025
@pljones
Copy link
Collaborator

pljones commented Jun 30, 2025

I'd have a change log entry - helps search engines help any looking up the issue find "use the latest version" should fix it.

// for windows only, check darkmode as proposed in https://www.qt.io/blog/dark-mode-on-windows-11-with-qt-6.5
const QPalette defaultPalette;
if ( defaultPalette.color ( QPalette::WindowText ).lightness() > defaultPalette.color ( QPalette::Window ).lightness() )
#else
if ( palette().color ( QPalette::Window ) == QColor::fromRgbF ( 0.196078, 0.196078, 0.196078, 1 ) )
Copy link
Collaborator

@pljones pljones Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this not also compare against a threshold? (Somewhere halfway between the two tones in use.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would then rather use the code above. But this worked for macOS and probably Linux (?).

Copy link
Collaborator

@pljones pljones Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do non-Q_OS_WINDOWS platforms have QPalette::Window? If they do, then we may as well use the same for all platforms if it works -- I'd rather have as few different ways of doing the same thing as possible.

We're looking to do "is colour scheme dark" -- if that means "is window text (EDIT: not darker) ligher than window background" and Qt supports getting the window text and window background colours in a way that supports the lightness() method, I can't think why we shouldn't do it the same on all.

(I really want to get rid of "does the window colour equal some random value that was present on someone's screen" -- most window managers allow a variety of colour schemes and this is as likely to be wrong for anyone customising the set up as it is right.)

Copy link
Member Author

@ann0see ann0see Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the link proposes the lightness comparison - so I assume that this is the Qt proposed way to go and it should work on all supported OS. I wanted to change as little behavior as possible, but yes - the new approach seems cleaner.

@ann0see ann0see force-pushed the bug/windowsDarkMode branch from f70841f to da2c04f Compare July 4, 2025 18:48
// for earlier versions, check darkmode as proposed in https://www.qt.io/blog/dark-mode-on-windows-11-with-qt-6.5
const QPalette defaultPalette;
if ( defaultPalette.color ( QPalette::WindowText ).lightness() > defaultPalette.color ( QPalette::Window ).lightness() )
#endif
{
// Dark mode on macOS/Linux needs a light color
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, this is now "Dark mode on QT before 6.5.0" rather than OS-specific.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Also out of scope, I'd rather we were using named CSS colours rather than magic incantations (what's wrong with "gainsboro" or "black"?).)

Copy link
Member Author

@ann0see ann0see Jul 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are not magic at all. rgb(x,y,z) or #ffffff are clearly defined color codes. In webdev I usually also don't use keywords as e.g. the hex value is more precise. Also IDEs usually show the color directly or can be configured to do so:

color picker in VSCodium

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point is, someone reading the code has to work out in their head what colour they are. I'd rather use "lightgray" than "gainsboro" for readability to be honest - I had to look up what the colour code was to see what (220, 220, 220) looked like and find the css name -- with "lightgray" I'd have a pretty good idea immediately.

Copy link
Collaborator

@pljones pljones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not fussed about my last comments.

@ann0see ann0see force-pushed the bug/windowsDarkMode branch from da2c04f to 462b6f0 Compare July 6, 2025 08:47
@ann0see ann0see merged commit 4fde19a into jamulussoftware:main Jul 23, 2025
11 checks passed
@github-project-automation github-project-automation bot moved this from Waiting on Team to Done in Tracking Jul 23, 2025
@ann0see ann0see deleted the bug/windowsDarkMode branch July 23, 2025 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Windows Windows runtime issue
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Windows 11 dark mode title does not show in correct color
2 participants