Skip to content

Commit 274358d

Browse files
authored
Add integration for QtQuick Controls 2 applications (#130)
This enables the QtQuick Controls 2 desktop style when it is available. Since the experience without it is really broken, QGnomePlatform now warns on the console when the style is not installed.
1 parent 2dd033d commit 274358d

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ find_package(Qt${QT_VERSION_MAJOR} ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
3636
DBus
3737
Gui
3838
Widgets
39+
QuickControls2
3940
)
4041

4142
find_package(Qt${QT_VERSION_MAJOR}Gui ${QT_MIN_VERSION} CONFIG REQUIRED Private)
@@ -51,6 +52,17 @@ else()
5152
find_package(AdwaitaQt "1.4.2" REQUIRED)
5253
endif()
5354

55+
56+
if (NOT USE_QT6)
57+
find_package(KF5QQC2DesktopStyle)
58+
set_package_properties(KF5QQC2DesktopStyle PROPERTIES
59+
DESCRIPTION "Styling for QtQuick Controls 2 applications"
60+
TYPE RUNTIME)
61+
else()
62+
# TODO, the desktop style for Qt6 is not yet released
63+
endif()
64+
65+
5466
find_package(PkgConfig REQUIRED)
5567
pkg_check_modules(GTK+3 REQUIRED IMPORTED_TARGET gtk+-3.0)
5668

src/theme/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ target_link_libraries(qgnomeplatformtheme
1616
Qt${QT_VERSION_MAJOR}::DBus
1717
Qt${QT_VERSION_MAJOR}::Gui
1818
Qt${QT_VERSION_MAJOR}::GuiPrivate
19+
Qt${QT_VERSION_MAJOR}::QuickControls2
1920
${ADWAITAQT_LIBRARIES}
2021
PkgConfig::GTK+3
2122
)

src/theme/qgnomeplatformtheme.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include <QApplication>
2727
#include <QGuiApplication>
28+
#include <QLoggingCategory>
29+
#include <QQuickStyle>
2830
#include <QStyleFactory>
2931

3032
#undef signals
@@ -43,6 +45,8 @@
4345
#include <QtGui/private/qgenericunixthemes_p.h>
4446
#endif
4547

48+
Q_LOGGING_CATEGORY(QGnomePlatformThemeLog, "qt.qpa.qgnomeplatform.theme")
49+
4650
void gtkMessageHandler(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer unused_data)
4751
{
4852
/* Silence false-positive Gtk warnings (we are using Xlib to set
@@ -87,6 +91,29 @@ QGnomePlatformTheme::QGnomePlatformTheme()
8791
// Load QGnomeTheme
8892
m_platformTheme = QGenericUnixTheme::createUnixTheme(QLatin1String("gnome"));
8993
#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"));
90117
}
91118

92119
QGnomePlatformTheme::~QGnomePlatformTheme()

0 commit comments

Comments
 (0)