27 QUrl url(QStringLiteral(
"file://"));
32 tmp.replace(QChar(
'\\'), QChar(
'/'));
35 if (QFileInfo(path).isAbsolute()) {
36 tmp = QStringLiteral(
"/") + tmp;
38 url.setPath(tmp, QUrl::DecodedMode);
41 url.setPath(path, QUrl::DecodedMode);
43 return QDesktopServices::openUrl(url);
81QMetaObject::Connection
onDarkModeChanged(std::function<
void(
bool)> &&darkModeChangedCallback, QObject *context,
bool invokeImmediately)
83#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
84 if (
const auto *
const styleHints = QGuiApplication::styleHints()) {
85 if (invokeImmediately) {
86 darkModeChangedCallback(styleHints->colorScheme() == Qt::ColorScheme::Dark);
88 return QObject::connect(styleHints, &QStyleHints::colorSchemeChanged, context,
89 [handler = std::move(darkModeChangedCallback)](Qt::ColorScheme colorScheme) {
return handler(colorScheme == Qt::ColorScheme::Dark); });
92 Q_UNUSED(darkModeChangedCallback)
94 Q_UNUSED(invokeImmediately)
96 return QMetaObject::Connection();
QT_UTILITIES_EXPORT QMetaObject::Connection onDarkModeChanged(std::function< void(bool)> &&darkModeChangedCallback, QObject *context=nullptr, bool invokeImmediately=true)
Invokes the specified callback when the color scheme changed.