summarylogtreecommitdiffstats
path: root/qt6ct-shenanigans.patch
blob: 2bc9fcf68bb7c299852888f10624f2e4992788de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 475a47f..d4950b3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,15 +28,19 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
 set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
 set(QT_NO_PRIVATE_MODULE_WARNING ON)
 
-add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060200 -DUSE_WIDGETS -DQT_DEPRECATED_WARNINGS -DQT_MESSAGELOGCONTEXT)
+add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060200 -DQT_DEPRECATED_WARNINGS -DQT_MESSAGELOGCONTEXT)
 add_compile_options(-Wall -Wextra)
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
 
-find_package(Qt6 6.2 CONFIG REQUIRED COMPONENTS BuildInternals Core Widgets OPTIONAL_COMPONENTS LinguistTools)
+find_package(Qt6 6.2 CONFIG REQUIRED COMPONENTS BuildInternals Core OPTIONAL_COMPONENTS Widgets QuickControls2 LinguistTools)
 if(Qt6_VERSION VERSION_GREATER_EQUAL 6.10)
-    find_package(Qt6 6.10 CONFIG REQUIRED COMPONENTS WidgetsPrivate GuiPrivate)
+    find_package(Qt6 6.10 CONFIG REQUIRED COMPONENTS GuiPrivate OPTIONAL_COMPONENTS WidgetsPrivate)
 endif()
 
+find_package(KF6Config)
+find_package(KF6ColorScheme)
+find_package(KF6IconThemes)
+
 get_target_property(QT_QTPATHS_EXECUTABLE Qt6::qtpaths IMPORTED_LOCATION)
 
 if(Qt6LinguistTools_FOUND)
@@ -80,10 +84,12 @@ endif()
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/qt6ct-common)
 
 add_link_options(-Wl,--no-undefined)
-add_subdirectory(src/qt6ct)
 add_subdirectory(src/qt6ct-common)
 add_subdirectory(src/qt6ct-qtplugin)
-add_subdirectory(src/qt6ct-style)
+if(Qt6Widgets_FOUND)
+    add_subdirectory(src/qt6ct-style)
+    add_subdirectory(src/qt6ct)
+endif()
 
 install(DIRECTORY qss DESTINATION ${CMAKE_INSTALL_DATADIR}/qt6ct)
 install(DIRECTORY colors DESTINATION ${CMAKE_INSTALL_DATADIR}/qt6ct)
diff --git a/src/qt6ct-common/CMakeLists.txt b/src/qt6ct-common/CMakeLists.txt
index 3b9f0b9..2afce8d 100644
--- a/src/qt6ct-common/CMakeLists.txt
+++ b/src/qt6ct-common/CMakeLists.txt
@@ -24,5 +24,6 @@ set(app_SRCS
 
 add_library(qt6ct-common SHARED ${app_SRCS})
 set_target_properties(qt6ct-common PROPERTIES VERSION ${QT6CT_VERSION})
-target_link_libraries(qt6ct-common PRIVATE Qt6::Gui)
+target_link_libraries(qt6ct-common PRIVATE Qt6::Gui $<TARGET_NAME_IF_EXISTS:KF6::ConfigCore> $<TARGET_NAME_IF_EXISTS:KF6::ColorScheme>)
+target_compile_definitions(qt6ct-common PRIVATE $<$<TARGET_EXISTS:KF6::ConfigCore>:KF_CONFIGCORE_LIB> $<$<TARGET_EXISTS:KF6::ColorScheme>:KF_COLORSCHEME_LIB>)
 install(TARGETS qt6ct-common DESTINATION ${CMAKE_INSTALL_LIBDIR})
diff --git a/src/qt6ct-common/qt6ct.cpp b/src/qt6ct-common/qt6ct.cpp
index 616440b..250987d 100644
--- a/src/qt6ct-common/qt6ct.cpp
+++ b/src/qt6ct-common/qt6ct.cpp
@@ -34,6 +34,10 @@
 #include <QFile>
 #include <QSettings>
 #include <QtDebug>
+#if defined KF_CONFIGCORE_LIB && defined KF_COLORSCHEME_LIB
+#include <KSharedConfig>
+#include <KColorScheme>
+#endif
 #include "qt6ct.h"
 
 #ifndef QT6CT_DATADIR
@@ -121,6 +125,9 @@ QStringList Qt6CT::sharedColorSchemePaths()
     for(const QString &p : QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation))
     {
         paths << (p + QStringLiteral("/qt6ct/colors"));
+#if defined KF_CONFIGCORE_LIB && defined KF_COLORSCHEME_LIB
+        paths << (p + QStringLiteral("/color-schemes"));
+#endif
     }
     paths << QStringLiteral(QT6CT_DATADIR"/qt6ct/colors");
     paths.removeDuplicates();
@@ -129,6 +136,9 @@ QStringList Qt6CT::sharedColorSchemePaths()
 
 QString Qt6CT::resolvePath(const QString &path)
 {
+    if(path.isEmpty())
+        return path;
+
     QString tmp = path;
     tmp.replace(QLatin1Char('~'), QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
     if(!tmp.contains(QLatin1Char('$')))
@@ -148,9 +158,21 @@ QString Qt6CT::resolvePath(const QString &path)
     return tmp;
 }
 
-QPalette Qt6CT::loadColorScheme(const QString &filePath, const QPalette &fallback)
+bool Qt6CT::isKColorScheme(const QString &filePath)
 {
-    QPalette customPalette;
+    return filePath.toLower().endsWith(".colors");
+}
+
+std::optional<QPalette> Qt6CT::loadColorScheme(const QString &filePath)
+{
+    if(filePath.isEmpty())
+        return std::nullopt;
+
+#if defined KF_CONFIGCORE_LIB && defined KF_COLORSCHEME_LIB
+    if(isKColorScheme(filePath))
+        return KColorScheme::createApplicationPalette(KSharedConfig::openConfig(filePath));
+#endif
+
     QSettings settings(filePath, QSettings::IniFormat);
     settings.beginGroup("ColorScheme"_L1);
     QStringList activeColors = settings.value("active_colors"_L1).toStringList();
@@ -158,7 +180,6 @@ QPalette Qt6CT::loadColorScheme(const QString &filePath, const QPalette &fallbac
     QStringList disabledColors = settings.value("disabled_colors"_L1).toStringList();
     settings.endGroup();
 
-
 #if (QT_VERSION >= QT_VERSION_CHECK(6,6,0))
     if(activeColors.count() == QPalette::Accent)
         activeColors << activeColors.at(QPalette::Highlight);
@@ -168,24 +189,19 @@ QPalette Qt6CT::loadColorScheme(const QString &filePath, const QPalette &fallbac
         disabledColors << disabledColors.at(QPalette::Highlight);
 #endif
 
+    if(activeColors.count() < QPalette::NColorRoles ||
+            inactiveColors.count() < QPalette::NColorRoles ||
+            disabledColors.count() < QPalette::NColorRoles)
+        return std::nullopt;
 
-    if(activeColors.count() >= QPalette::NColorRoles &&
-            inactiveColors.count() >= QPalette::NColorRoles &&
-            disabledColors.count() >= QPalette::NColorRoles)
-    {
-        for (int i = 0; i < QPalette::NColorRoles; i++)
-        {
-            QPalette::ColorRole role = QPalette::ColorRole(i);
-            customPalette.setColor(QPalette::Active, role, QColor(activeColors.at(i)));
-            customPalette.setColor(QPalette::Inactive, role, QColor(inactiveColors.at(i)));
-            customPalette.setColor(QPalette::Disabled, role, QColor(disabledColors.at(i)));
-        }
-    }
-    else
+    QPalette customPalette;
+    for (int i = 0; i < QPalette::NColorRoles; i++)
     {
-        customPalette = fallback; //load fallback palette
+        QPalette::ColorRole role = QPalette::ColorRole(i);
+        customPalette.setColor(QPalette::Active, role, QColor(activeColors.at(i)));
+        customPalette.setColor(QPalette::Inactive, role, QColor(inactiveColors.at(i)));
+        customPalette.setColor(QPalette::Disabled, role, QColor(disabledColors.at(i)));
     }
-
     return customPalette;
 }
 
diff --git a/src/qt6ct-common/qt6ct.h b/src/qt6ct-common/qt6ct.h
index f253987..06ea440 100644
--- a/src/qt6ct-common/qt6ct.h
+++ b/src/qt6ct-common/qt6ct.h
@@ -101,7 +101,8 @@ public:
     static QString styleColorSchemeFile();
     static QStringList sharedColorSchemePaths();
     static QString resolvePath(const QString &path);
-    static QPalette loadColorScheme(const QString &filePath, const QPalette &fallback);
+    static bool isKColorScheme(const QString &filePath);
+    static std::optional<QPalette> loadColorScheme(const QString &filePath);
 
     static void registerStyleInstance(StyleInstance *instance);
     static void unregisterStyleInstance(StyleInstance *instance);
diff --git a/src/qt6ct-qtplugin/CMakeLists.txt b/src/qt6ct-qtplugin/CMakeLists.txt
index 93a2b84..5e170c5 100644
--- a/src/qt6ct-qtplugin/CMakeLists.txt
+++ b/src/qt6ct-qtplugin/CMakeLists.txt
@@ -7,5 +7,6 @@ set(app_SRCS
 
 add_library(qt6ct-qtplugin MODULE ${app_SRCS})
 set_target_properties(qt6ct-qtplugin PROPERTIES OUTPUT_NAME qt6ct)
-target_link_libraries(qt6ct-qtplugin PRIVATE Qt6::Widgets Qt6::GuiPrivate qt6ct-common)
+target_link_libraries(qt6ct-qtplugin PRIVATE $<TARGET_NAME_IF_EXISTS:Qt6::WidgetsPrivate> Qt6::GuiPrivate $<TARGET_NAME_IF_EXISTS:Qt6::QuickControls2> $<TARGET_NAME_IF_EXISTS:KF6::IconThemes> qt6ct-common)
+target_compile_definitions(qt6ct-qtplugin PRIVATE $<$<TARGET_EXISTS:KF6::IconThemes>:KF_ICONTHEMES_LIB>)
 install(TARGETS qt6ct-qtplugin DESTINATION ${PLUGINDIR}/platformthemes)
diff --git a/src/qt6ct-qtplugin/qt6ct-qtplugin.pro b/src/qt6ct-qtplugin/qt6ct-qtplugin.pro
index f3e9ef6..a05a9b7 100644
--- a/src/qt6ct-qtplugin/qt6ct-qtplugin.pro
+++ b/src/qt6ct-qtplugin/qt6ct-qtplugin.pro
@@ -11,7 +11,7 @@ SOURCES += \
     qt6ctplatformtheme.cpp
 
 !equals(DISABLE_WIDGETS,1) {
-   QT += widgets
+   QT += widgets widgets-private
 }
 
 OTHER_FILES += qt6ct.json
diff --git a/src/qt6ct-qtplugin/qt6ctplatformtheme.cpp b/src/qt6ct-qtplugin/qt6ctplatformtheme.cpp
index 569b13f..3969621 100644
--- a/src/qt6ct-qtplugin/qt6ctplatformtheme.cpp
+++ b/src/qt6ct-qtplugin/qt6ctplatformtheme.cpp
@@ -41,38 +41,59 @@
 #include <QStyleFactory>
 #include <QApplication>
 #include <QWidget>
+#if QT_CONFIG(graphicsview)
+#include <QGraphicsScene>
+#endif
+#include <private/qapplication_p.h>
 #endif
 #include <QFile>
 #include <QFileSystemWatcher>
-#include <private/qiconloader_p.h>
+#ifdef QT_QUICKCONTROLS2_LIB
+#include <QQuickStyle>
+#endif
 
 #include "qt6ct.h"
 #include "qt6ctplatformtheme.h"
 
 #include <QStringList>
 #include <qpa/qplatformthemefactory_p.h>
+#include <qpa/qwindowsysteminterface.h>
+
+#ifdef KF_ICONTHEMES_LIB
+#include <KIconEngine>
+#include <KIconLoader>
+#endif
 
 Q_LOGGING_CATEGORY(lqt6ct, "qt6ct", QtWarningMsg)
 
 //QT_QPA_PLATFORMTHEME=qt6ct
 
-Qt6CTPlatformTheme::Qt6CTPlatformTheme()
+Qt6CTPlatformTheme::Qt6CTPlatformTheme() :
+    m_generalFont(*QGenericUnixTheme::font(QPlatformTheme::SystemFont)),
+    m_fixedFont(*QGenericUnixTheme::font(QPlatformTheme::FixedFont))
 {
     Qt6CT::initConfig();
     if(QGuiApplication::desktopSettingsAware())
     {
         readSettings();
         QMetaObject::invokeMethod(this, &Qt6CTPlatformTheme::applySettings, Qt::QueuedConnection);
-#ifdef QT_WIDGETS_LIB
         QMetaObject::invokeMethod(this, &Qt6CTPlatformTheme::createFSWatcher, Qt::QueuedConnection);
+        //must be applied before Q_COREAPP_STARTUP_FUNCTION execution
+        if(Qt6CT::isKColorScheme(m_schemePath))
+            qApp->setProperty("KDE_COLOR_SCHEME_PATH", m_schemePath);
+#if defined QT_WIDGETS_LIB && defined QT_QUICKCONTROLS2_LIB
+        if(hasWidgets())
+            //don't override the value explicitly set by the user
+            if(QQuickStyle::name().isEmpty() || QQuickStyle::name() == QLatin1String("Fusion"))
+                QQuickStyle::setStyle(QLatin1String("org.kde.desktop"));
 #endif
-        QGuiApplication::setFont(m_generalFont);
     }
     qCDebug(lqt6ct) << "using qt6ct plugin";
 #ifdef QT_WIDGETS_LIB
     if(!QStyleFactory::keys().contains(u"qt6ct-style"_s))
         qCCritical(lqt6ct) << "unable to find qt6ct proxy style";
 #endif
+    QCoreApplication::instance()->installEventFilter(this);
 }
 
 Qt6CTPlatformTheme::~Qt6CTPlatformTheme()
@@ -92,8 +113,8 @@ QPlatformDialogHelper *Qt6CTPlatformTheme::createPlatformDialogHelper(DialogType
 
 const QPalette *Qt6CTPlatformTheme::palette(QPlatformTheme::Palette type) const
 {
-    if (type == QPlatformTheme::SystemPalette && !m_isIgnored)
-        return &m_palette;
+    if (type == QPlatformTheme::SystemPalette && m_palette)
+        return &*m_palette;
     return QGenericUnixTheme::palette(type);
 }
 
@@ -148,6 +169,13 @@ QIcon Qt6CTPlatformTheme::fileIcon(const QFileInfo &fileInfo, QPlatformTheme::Ic
     return QIcon::fromTheme(type.iconName());
 }
 
+#ifdef KF_ICONTHEMES_LIB
+QIconEngine *Qt6CTPlatformTheme::createIconEngine(const QString &iconName) const
+{
+    return new KIconEngine(iconName, KIconLoader::global());
+}
+#endif
+
 void Qt6CTPlatformTheme::applySettings()
 {
     if(!QGuiApplication::desktopSettingsAware() || m_isIgnored)
@@ -156,18 +184,18 @@ void Qt6CTPlatformTheme::applySettings()
         return;
     }
 
-    QGuiApplication::setFont(m_generalFont); //apply font
+    if(Qt6CT::isKColorScheme(m_schemePath))
+        qApp->setProperty("KDE_COLOR_SCHEME_PATH", m_schemePath);
+    else if(m_update)
+        qApp->setProperty("KDE_COLOR_SCHEME_PATH", QVariant());
 
 #ifdef QT_WIDGETS_LIB
     if(hasWidgets())
     {
-        qApp->setFont(m_generalFont);
-
-        //Qt 5.6 or higher should be use themeHint function on application startup.
-        //So, there is no need to call this function first time.
         if(m_update)
         {
-            qApp->setWheelScrollLines(m_wheelScrollLines);
+            if(FontHash *hash = qt_app_fonts_hash(); hash && hash->size())
+                hash->clear();
             Qt6CT::reloadStyleInstanceSettings();
         }
 
@@ -193,25 +221,26 @@ void Qt6CTPlatformTheme::applySettings()
 
     if(m_update)
     {
-        QIconLoader::instance()->updateSystemTheme(); //apply icons
-        QGuiApplication::setPalette(QGuiApplication::palette()); //apply palette
+        QWindowSystemInterface::handleThemeChange();
+        QCoreApplication::postEvent(qGuiApp, new QEvent(QEvent::ApplicationFontChange));
     }
 
 #ifdef QT_WIDGETS_LIB
     if(hasWidgets() && m_update)
     {
-        for(QWidget *w : qApp->allWidgets())
-        {
-            QEvent e(QEvent::ThemeChange);
-            QApplication::sendEvent(w, &e);
-        }
+#if QT_CONFIG(graphicsview)
+        for(auto scene : std::as_const(QApplicationPrivate::instance()->scene_list))
+            QCoreApplication::postEvent(scene, new QEvent(QEvent::ApplicationFontChange));
+#endif
+
+        for(QWidget *w : QApplication::allWidgets())
+            QCoreApplication::postEvent(w, new QEvent(QEvent::ThemeChange));
     }
 #endif
 
     m_update = true;
 }
 
-#ifdef QT_WIDGETS_LIB
 void Qt6CTPlatformTheme::createFSWatcher()
 {
     QFileSystemWatcher *watcher = new QFileSystemWatcher(this);
@@ -230,7 +259,6 @@ void Qt6CTPlatformTheme::updateSettings()
     readSettings();
     applySettings();
 }
-#endif
 
 void Qt6CTPlatformTheme::readSettings()
 {
@@ -238,13 +266,10 @@ void Qt6CTPlatformTheme::readSettings()
 
     settings.beginGroup("Appearance"_L1);
     m_style = settings.value("style"_L1, u"Fusion"_s).toString();
-    m_palette = *QGenericUnixTheme::palette(SystemPalette);
-    QString schemePath = settings.value("color_scheme_path"_L1).toString();
-    if(!schemePath.isEmpty() && settings.value("custom_palette"_L1, false).toBool())
-    {
-        schemePath = Qt6CT::resolvePath(schemePath); //replace environment variables
-        m_palette = Qt6CT::loadColorScheme(schemePath, m_palette);
-    }
+    m_schemePath = !m_isIgnored && settings.value("custom_palette"_L1, false).toBool()
+        ? Qt6CT::resolvePath(settings.value("color_scheme_path"_L1).toString()) //replace environment variables
+        : QString();
+    m_palette = Qt6CT::loadColorScheme(m_schemePath);
     m_iconTheme = settings.value("icon_theme"_L1).toString();
     //load dialogs
     if(!m_update)
@@ -262,10 +287,10 @@ void Qt6CTPlatformTheme::readSettings()
     settings.endGroup();
 
     settings.beginGroup("Fonts"_L1);
-    m_generalFont = QGuiApplication::font();
-    m_generalFont.fromString(settings.value("general"_L1, QGuiApplication::font()).toString());
-    m_fixedFont = QGuiApplication::font();
-    m_fixedFont.fromString(settings.value("fixed"_L1, QGuiApplication::font()).toString());
+    m_generalFont = *QGenericUnixTheme::font(QPlatformTheme::SystemFont);
+    m_generalFont.fromString(settings.value("general"_L1).toString());
+    m_fixedFont = *QGenericUnixTheme::font(QPlatformTheme::FixedFont);
+    m_fixedFont.fromString(settings.value("fixed_L1").toString());
     settings.endGroup();
 
     settings.beginGroup("Interface"_L1);
@@ -354,3 +379,17 @@ QString Qt6CTPlatformTheme::loadStyleSheets(const QStringList &paths)
     content.replace(regExp, u"\n"_s);
     return content;
 }
+
+//There's such a thing as KColorSchemeManager that lets the user to change the color scheme
+//application-wide and we should re-apply the color scheme if KCSM resets it to the default
+//which leads KColorScheme to get the color scheme from kdeglobals which won't help us.
+bool Qt6CTPlatformTheme::eventFilter(QObject *obj, QEvent *e)
+{
+    if(obj == qApp &&
+            e->type() == QEvent::DynamicPropertyChange &&
+            static_cast<QDynamicPropertyChangeEvent*>(e)->propertyName() == "KDE_COLOR_SCHEME_PATH" &&
+            qApp->property("KDE_COLOR_SCHEME_PATH").toString().isEmpty() &&
+            Qt6CT::isKColorScheme(m_schemePath))
+        applySettings();
+    return QObject::eventFilter(obj, e);
+}
diff --git a/src/qt6ct-qtplugin/qt6ctplatformtheme.h b/src/qt6ct-qtplugin/qt6ctplatformtheme.h
index b2a7bcf..e8cf68a 100644
--- a/src/qt6ct-qtplugin/qt6ctplatformtheme.h
+++ b/src/qt6ct-qtplugin/qt6ctplatformtheme.h
@@ -66,16 +66,19 @@ public:
     //virtual QPixmap fileIconPixmap(const QFileInfo &fileInfo, const QSizeF &size,
     //                               QPlatformTheme::IconOptions iconOptions = 0) const;
 
-    //virtual QIconEngine *createIconEngine(const QString &iconName) const;
+#ifdef KF_ICONTHEMES_LIB
+    virtual QIconEngine *createIconEngine(const QString &iconName) const override;
+#endif
     //virtual QList<QKeySequence> keyBindings(QKeySequence::StandardKey key) const;
     //virtual QString standardButtonText(int button) const;
 
+protected:
+    bool eventFilter(QObject *obj, QEvent *e) override;
+
 private slots:
     void applySettings();
-#ifdef QT_WIDGETS_LIB
     void createFSWatcher();
     void updateSettings();
-#endif
 
 private:
     void readSettings();
@@ -83,8 +86,8 @@ private:
     bool hasWidgets();
 #endif
     QString loadStyleSheets(const QStringList &paths);
-    QString m_style, m_iconTheme, m_userStyleSheet, m_prevStyleSheet;
-    QPalette m_palette;
+    QString m_style, m_schemePath, m_iconTheme, m_userStyleSheet, m_prevStyleSheet;
+    std::optional<QPalette> m_palette;
     QFont m_generalFont, m_fixedFont;
     int m_doubleClickInterval;
     int m_cursorFlashTime;
diff --git a/src/qt6ct-style/CMakeLists.txt b/src/qt6ct-style/CMakeLists.txt
index 5ab1c21..c8870b3 100644
--- a/src/qt6ct-style/CMakeLists.txt
+++ b/src/qt6ct-style/CMakeLists.txt
@@ -1,7 +1,5 @@
 project(qt6ct-style)
 
-add_definitions(-DUSE_WIDGETS)
-
 set(app_SRCS
   plugin.cpp
   qt6ctproxystyle.cpp
diff --git a/src/qt6ct/CMakeLists.txt b/src/qt6ct/CMakeLists.txt
index fb0e1f7..f11071f 100644
--- a/src/qt6ct/CMakeLists.txt
+++ b/src/qt6ct/CMakeLists.txt
@@ -31,6 +31,7 @@ if(Qt6LinguistTools_FOUND)
 endif()
 
 add_executable(qt6ct ${app_SRCS})
-target_link_libraries(qt6ct PRIVATE Qt6::Widgets Qt6::WidgetsPrivate qt6ct-common)
+target_link_libraries(qt6ct PRIVATE Qt6::Widgets Qt6::GuiPrivate $<TARGET_NAME_IF_EXISTS:KF6::ConfigCore> qt6ct-common)
+target_compile_definitions(qt6ct PRIVATE USE_WIDGETS $<$<TARGET_EXISTS:KF6::ConfigCore>:KF_CONFIGCORE_LIB> $<$<TARGET_EXISTS:KF6::ColorScheme>:KF_COLORSCHEME_LIB>)
 install(TARGETS qt6ct DESTINATION ${CMAKE_INSTALL_BINDIR})
 install(FILES qt6ct.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
diff --git a/src/qt6ct/appearancepage.cpp b/src/qt6ct/appearancepage.cpp
index 2f1faf8..0c01d4a 100644
--- a/src/qt6ct/appearancepage.cpp
+++ b/src/qt6ct/appearancepage.cpp
@@ -35,6 +35,9 @@
 #include <QMenu>
 #include <QIcon>
 #include <QStringList>
+#ifdef KF_CONFIGCORE_LIB
+#include <KConfigGroup>
+#endif
 #include <qpa/qplatformthemefactory_p.h>
 #include <qpa/qplatformtheme.h>
 #include "qt6ct.h"
@@ -70,7 +73,7 @@ AppearancePage::AppearancePage(QWidget *parent) :
     QMenu *menu = new QMenu(this);
     menu->addAction(QIcon::fromTheme(u"document-new"_s), tr("Create"), this, qOverload<>(&AppearancePage::createColorScheme));
     m_changeColorSchemeAction = menu->addAction(QIcon::fromTheme(u"accessories-text-editor"_s), tr("Edit"), this, &AppearancePage::changeColorScheme);
-    menu->addAction(QIcon::fromTheme(u"edit-copy"_s), tr("Create a Copy"), this, &AppearancePage::copyColorScheme);
+    m_copyColorSchemeAction = menu->addAction(QIcon::fromTheme(u"edit-copy"_s), tr("Create a Copy"), this, &AppearancePage::copyColorScheme);
     m_renameColorSchemeAction = menu->addAction(tr("Rename"), this, &AppearancePage::renameColorScheme);
     menu->addSeparator();
     m_removeColorSchemeAction = menu->addAction(QIcon::fromTheme(u"edit-delete"_s), tr("Remove"), this, &AppearancePage::removeColorScheme);
@@ -126,6 +129,15 @@ void AppearancePage::writeSettings(QSettings *settings)
     settings->endGroup();
 }
 
+#ifdef KF_CONFIGCORE_LIB
+void AppearancePage::writeSettings(KSharedConfigPtr config)
+{
+    KConfigGroup group(config, "KDE");
+    group.writeEntry("widgetStyle", "qt6ct-style");
+    group.sync();
+}
+#endif
+
 void AppearancePage::on_styleComboBox_textActivated(const QString &text)
 {
     QStyle *style = QStyleFactory::create(text);
@@ -157,7 +169,7 @@ void AppearancePage::on_colorSchemeComboBox_activated(int)
     }
     else
     {
-        m_customPalette = Qt6CT::loadColorScheme(data, palette());
+        m_customPalette = Qt6CT::loadColorScheme(data).value_or(palette());
     }
     updatePalette();
 }
@@ -333,6 +345,7 @@ void AppearancePage::setPreviewPalette(const QPalette &p)
 
 void AppearancePage::updateActions()
 {
+    m_copyColorSchemeAction->setVisible(!Qt6CT::isKColorScheme(m_ui->colorSchemeComboBox->currentData().toString()));
     if(m_ui->colorSchemeComboBox->count() == 0 ||
             !QFileInfo(m_ui->colorSchemeComboBox->currentData().toString()).isWritable())
     {
@@ -364,8 +377,7 @@ void AppearancePage::readSettings()
     QString style = settings.value("style"_L1, u"Fusion"_s).toString();
     m_ui->styleComboBox->setCurrentText(style);
 
-    QString colorSchemePath = settings.value("color_scheme_path"_L1).toString();
-    colorSchemePath = Qt6CT::resolvePath(colorSchemePath); //replace environment variables
+    QString colorSchemePath = Qt6CT::resolvePath(settings.value("color_scheme_path").toString()); //replace environment variables
 
     m_ui->colorSchemeComboBox->addItem(tr("Default"), u"system"_s);
     m_ui->colorSchemeComboBox->addItem(tr("Style's colors"), u"style"_s);
@@ -382,7 +394,7 @@ void AppearancePage::readSettings()
             index = m_ui->colorSchemeComboBox->findData(u"style"_s);
 
         m_ui->colorSchemeComboBox->setCurrentIndex(index);
-        m_customPalette = Qt6CT::loadColorScheme(colorSchemePath, palette());
+        m_customPalette = Qt6CT::loadColorScheme(colorSchemePath).value_or(palette());
     }
     else
     {        
@@ -428,11 +440,26 @@ void AppearancePage::findColorSchemes(const QString &path)
 {
     QDir dir(path);
     dir.setFilter(QDir::Files);
-    dir.setNameFilters({ u"*.conf"_s });
+    QStringList nameFilters;
+    nameFilters << u"*.conf"_s;
+#if defined KF_CONFIGCORE_LIB && defined KF_COLORSCHEME_LIB
+    nameFilters << u"*.colors"_s;
+#endif
+    dir.setNameFilters(nameFilters);
 
     for(const QFileInfo &info : dir.entryInfoList())
     {
-        m_ui->colorSchemeComboBox->addItem(info.baseName(), info.filePath());
+        QString name = info.baseName();
+        QString path = info.filePath();
+#if defined KF_CONFIGCORE_LIB && defined KF_COLORSCHEME_LIB
+        if(Qt6CT::isKColorScheme(path))
+        {
+            KSharedConfigPtr config = KSharedConfig::openConfig(path, KConfig::SimpleConfig);
+            KConfigGroup group(config, "General");
+            name = group.readEntry("Name", name) + " (KColorScheme)";
+        }
+#endif
+        m_ui->colorSchemeComboBox->addItem(name, path);
     }
 }
 
diff --git a/src/qt6ct/appearancepage.h b/src/qt6ct/appearancepage.h
index e196b62..8e4902e 100644
--- a/src/qt6ct/appearancepage.h
+++ b/src/qt6ct/appearancepage.h
@@ -49,6 +49,10 @@ public:
 
     void writeSettings(QSettings *settings) override;
 
+#ifdef KF_CONFIGCORE_LIB
+    void writeSettings(KSharedConfigPtr config) override;
+#endif
+
 private slots:
     void on_styleComboBox_textActivated(const QString &text);
     void on_colorSchemeComboBox_activated(int);
@@ -73,7 +77,7 @@ private:
     QStyle *m_selectedStyle = nullptr;
     QPalette m_customPalette;
     QWidget *m_previewWidget;
-    QAction *m_changeColorSchemeAction, *m_renameColorSchemeAction, *m_removeColorSchemeAction;
+    QAction *m_changeColorSchemeAction, *m_copyColorSchemeAction, *m_renameColorSchemeAction, *m_removeColorSchemeAction;
     Ui::PreviewForm *m_previewUi;
 };
 
diff --git a/src/qt6ct/fontspage.cpp b/src/qt6ct/fontspage.cpp
index 75de0fd..ae0f091 100644
--- a/src/qt6ct/fontspage.cpp
+++ b/src/qt6ct/fontspage.cpp
@@ -29,6 +29,7 @@
 #include <QMessageBox>
 #include <QSettings>
 #include <QApplication>
+#include <QFontDatabase>
 #include <QFontDialog>
 #include <QDir>
 #include <QFile>
@@ -70,12 +71,19 @@ void FontsPage::onFontChangeRequested(QWidget *widget)
 {
     bool ok = false;
     QFont font = QFontDialog::getFont (&ok, widget->font(), this);
-    if(ok)
-    {
-        widget->setProperty("value", font.toString());
-        widget->setFont(font);
-        qobject_cast<QLabel*>(widget)->setText(font.family () + QChar::Space + QString::number(font.pointSize ()));
-    }
+    if(!ok)
+        return;
+
+    if(font.weight() == QFont::Normal
+        && (font.styleName() == "Regular"_L1
+            || font.styleName() == "Normal"_L1
+            || font.styleName() == "Book"_L1
+            || font.styleName() == "Roman"_L1))
+        font.setStyleName(QString());
+
+    widget->setProperty("value", font.toString());
+    widget->setFont(font);
+    qobject_cast<QLabel*>(widget)->setText(font.family () + QChar::Space + QString::number(font.pointSize ()));
 }
 
 void FontsPage::readSettings()
@@ -89,8 +97,9 @@ void FontsPage::readSettings()
 
 void FontsPage::loadFont(QSettings *settings, QLabel *label, const QString &key)
 {
-    QFont font = QApplication::font();
-    font.fromString(settings->value(key, QApplication::font().toString()).toString());
+    QFont font = settings->value(key, key == "fixed"_L1
+        ? QFontDatabase::systemFont(QFontDatabase::FixedFont)
+        : QFontDatabase::systemFont(QFontDatabase::GeneralFont)).value<QFont>();
     label->setText(font.family() + QChar::Space + QString::number(font.pointSize()));
     label->setFont(font);
     label->setProperty("value", font.toString());
diff --git a/src/qt6ct/iconthemepage.cpp b/src/qt6ct/iconthemepage.cpp
index 37960f9..9156116 100644
--- a/src/qt6ct/iconthemepage.cpp
+++ b/src/qt6ct/iconthemepage.cpp
@@ -34,6 +34,9 @@
 #include <QProgressBar>
 #include <QMetaObject>
 #include <QThread>
+#ifdef KF_CONFIGCORE_LIB
+#include <KConfigGroup>
+#endif
 #include "qt6ct.h"
 #include "iconthemepage.h"
 #include "ui_iconthemepage.h"
@@ -71,6 +74,19 @@ void IconThemePage::writeSettings(QSettings *settings)
         settings->setValue("Appearance/icon_theme"_L1, item->data(3, Qt::UserRole));
 }
 
+#ifdef KF_CONFIGCORE_LIB
+void IconThemePage::writeSettings(KSharedConfigPtr config)
+{
+    QTreeWidgetItem *item = m_ui->treeWidget->currentItem();
+    if(!item)
+        return;
+
+    KConfigGroup group(config, "Icons");
+    group.writeEntry("Theme", item->data(3, Qt::UserRole));
+    group.sync();
+}
+#endif
+
 void IconThemePage::onFinished()
 {
     m_ui->treeWidget->addTopLevelItems(m_items);
diff --git a/src/qt6ct/iconthemepage.h b/src/qt6ct/iconthemepage.h
index 8938671..9ad3580 100644
--- a/src/qt6ct/iconthemepage.h
+++ b/src/qt6ct/iconthemepage.h
@@ -51,6 +51,10 @@ public:
 
     void writeSettings(QSettings *settings) override;
 
+#ifdef KF_CONFIGCORE_LIB
+    void writeSettings(KSharedConfigPtr config) override;
+#endif
+
 private slots:
     void onFinished();
 
diff --git a/src/qt6ct/mainwindow.cpp b/src/qt6ct/mainwindow.cpp
index 122dff2..10296a4 100644
--- a/src/qt6ct/mainwindow.cpp
+++ b/src/qt6ct/mainwindow.cpp
@@ -91,11 +91,19 @@ void MainWindow::on_buttonBox_clicked(QAbstractButton *button)
     if(id == QDialogButtonBox::Ok || id == QDialogButtonBox::Apply)
     {
         QSettings settings(Qt6CT::configFile(), QSettings::IniFormat);
+#ifdef KF_CONFIGCORE_LIB
+        KSharedConfigPtr config = KSharedConfig::openConfig("kdeglobals");
+#endif
         for(int i = 0; i < m_ui->tabWidget->count(); ++i)
         {
             TabPage *p = qobject_cast<TabPage*>(m_ui->tabWidget->widget(i));
             if(p)
+            {
                 p->writeSettings(&settings);
+#ifdef KF_CONFIGCORE_LIB
+                p->writeSettings(config);
+#endif
+            }
         }
     }
 
diff --git a/src/qt6ct/tabpage.h b/src/qt6ct/tabpage.h
index c77b5a7..4e46ddd 100644
--- a/src/qt6ct/tabpage.h
+++ b/src/qt6ct/tabpage.h
@@ -32,6 +32,10 @@
 #include <QWidget>
 #include <QSettings>
 
+#ifdef KF_CONFIGCORE_LIB
+#include <KSharedConfig>
+#endif
+
 class TabPage : public QWidget
 {
     Q_OBJECT
@@ -39,6 +43,10 @@ public:
     explicit TabPage(QWidget *parent = nullptr);
 
     virtual void writeSettings(QSettings *settings) = 0;
+
+#ifdef KF_CONFIGCORE_LIB
+    virtual void writeSettings(KSharedConfigPtr config) {}
+#endif
 };
 
 #endif // TABPAGE_H