|
25 | 25 |
|
26 | 26 | #include <QApplication>
|
27 | 27 | #include <QGuiApplication>
|
| 28 | +#include <QLoggingCategory> |
| 29 | +#include <QQuickStyle> |
28 | 30 | #include <QStyleFactory>
|
29 | 31 |
|
30 | 32 | #undef signals
|
|
43 | 45 | #include <QtGui/private/qgenericunixthemes_p.h>
|
44 | 46 | #endif
|
45 | 47 |
|
| 48 | +Q_LOGGING_CATEGORY(QGnomePlatformThemeLog, "qt.qpa.qgnomeplatform.theme") |
| 49 | + |
46 | 50 | void gtkMessageHandler(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer unused_data)
|
47 | 51 | {
|
48 | 52 | /* Silence false-positive Gtk warnings (we are using Xlib to set
|
@@ -87,6 +91,29 @@ QGnomePlatformTheme::QGnomePlatformTheme()
|
87 | 91 | // Load QGnomeTheme
|
88 | 92 | m_platformTheme = QGenericUnixTheme::createUnixTheme(QLatin1String("gnome"));
|
89 | 93 | #endif
|
| 94 | + |
| 95 | + // Configure the Qt Quick Controls 2 style to the KDE desktop style, |
| 96 | + // Which passes the QtWidgets theme through to Qt Quick Controls. |
| 97 | + // From https://invent.kde.org/plasma/plasma-integration/-/blob/02fe12a55522a43de3efa6de2185a695ff2a576a/src/platformtheme/kdeplatformtheme.cpp#L582 |
| 98 | + |
| 99 | + // if the user has explicitly set something else, don't meddle |
| 100 | + // Also ignore the default Fusion style |
| 101 | + if (!QQuickStyle::name().isEmpty() && QQuickStyle::name() != QLatin1String("Fusion")) { |
| 102 | + return; |
| 103 | + } |
| 104 | + |
| 105 | + // Unfortunately we only have a way to check this on Qt5 |
| 106 | + // On Qt6 this should just fall back to the Fusion style automatically. |
| 107 | +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
| 108 | + if (!QQuickStyle::availableStyles().contains(QStringLiteral("org.kde.desktop"))) { |
| 109 | + qCWarning(QGnomePlatformThemeLog) << "The desktop style for QtQuick Controls 2 applications" |
| 110 | + << "is not available on the system (qqc2-desktop-style)." |
| 111 | + << "The application may look broken."; |
| 112 | + return; |
| 113 | + } |
| 114 | +#endif |
| 115 | + |
| 116 | + QQuickStyle::setStyle(QStringLiteral("org.kde.desktop")); |
90 | 117 | }
|
91 | 118 |
|
92 | 119 | QGnomePlatformTheme::~QGnomePlatformTheme()
|
|
0 commit comments