Urgent.News

What's breaking now, across thousands of outlets.

Tech

How to Change Themes with the Operating System in a Qt App

It turns out, I got the timeline wrong. The first bit of work I did on Packet Sender was to test light mode. See, Dan Nagle, creator and maintainer of Packet Sender, had implemented light and dark mode. But he only uses dark mode personally. Because of this, he missed the fact that some parts of the dark mode theme was hanging on after the app switched to light mode. Having fixed the bug, he…

When creating a Qt app, changing themes involves understanding how the operating system's light or dark mode settings interact with the app's theme. Initially, the author tested light mode in Packet Sender, a messaging app developed by Dan Nagle, who only uses dark mode personally. This led to a bug where some dark mode theme elements remained even after switching to light mode.

To fix this, the app needed to manually test the UI going from dark to light mode. It was discovered that Packet Sender followed the operating system's theme settings, but there was an additional setting built into the app that could be toggled for manual testing. After switching the operating system's mode, Packet Sender would read the new setting and apply the correct theme upon launch.

However, the app did not update itself when the OS changed themes automatically based on time or light conditions. Dan suggested using a thread to solve the problem, but the solution using a QThread crashed. It was realized that listening for light/dark changes was a GUI-state problem, not a background-compute issue. The optimal solution was to use a QTimer on the main thread, which runs in the same thread as the widgets and serializes the process with theme events.

This approach is safe on macOS and avoids race conditions. Ultimately, a function named setupThemePolling() was created to continuously poll the system's theme and apply the appropriate theme to the app, ensuring a smooth user experience without race conditions.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

500+ commits in five months: how I single-handedly launched RetroPoint

Пятого апреля 2026 года я начал проверять гипотезу: можно ли собрать работающий MVP SaaS за месяц на подписке Cursor за $20, работая по три-четыре часа четыре вечера в неделю. Через месяц MVP был.

One does not simply @Inject in TPF

I remember IntelliJ IDEA constantly nudging me away from field injection and toward constructor parameters. Funny how relevant that feels now. The principle was sound: make dependencies explicit.

More from Thursday 3 September →