summarylogtreecommitdiffstats
path: root/qt6ct-shenanigans.patch
blob: 085fd30e60ed6b58b6cf87317ea61d4cabf610a4 (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
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d6b608c..e54f9c2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -22,9 +22,12 @@ set(CMAKE_AUTORCC ON)
 set(CMAKE_AUTOUIC ON)
 set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
 
-add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000 -DUSE_WIDGETS)
+add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000)
 
-find_package(Qt6 REQUIRED COMPONENTS BuildInternals Core Widgets OPTIONAL_COMPONENTS LinguistTools)
+find_package(Qt6 REQUIRED COMPONENTS BuildInternals Core Gui OPTIONAL_COMPONENTS Widgets QuickControls2 LinguistTools)
+find_package(KF6Config)
+find_package(KF6ColorScheme)
+find_package(KF6IconThemes)
 
 get_target_property(QT_QTPATHS_EXECUTABLE Qt6::qtpaths IMPORTED_LOCATION)
 
@@ -50,8 +53,10 @@ if(Qt6LinguistTools_FOUND)
     endif()
 endif()
 
-#execute_process(COMMAND ${QT_QTPATHS_EXECUTABLE} -query QT_INSTALL_PLUGINS OUTPUT_VARIABLE PLUGINDIR OUTPUT_STRIP_TRAILING_WHITESPACE)
-execute_process(COMMAND ${QT_QTPATHS_EXECUTABLE} --plugin-dir OUTPUT_VARIABLE PLUGINDIR OUTPUT_STRIP_TRAILING_WHITESPACE)
+if(NOT PLUGINDIR)
+    #execute_process(COMMAND ${QT_QTPATHS_EXECUTABLE} -query QT_INSTALL_PLUGINS OUTPUT_VARIABLE PLUGINDIR OUTPUT_STRIP_TRAILING_WHITESPACE)
+    execute_process(COMMAND ${QT_QTPATHS_EXECUTABLE} --plugin-dir OUTPUT_VARIABLE PLUGINDIR OUTPUT_STRIP_TRAILING_WHITESPACE)
+endif()
 
 if(PLUGINDIR)
    message(STATUS "Plugin path: ${PLUGINDIR}")
@@ -67,10 +72,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 f748167..422dd3d 100644
--- a/src/qt6ct-common/CMakeLists.txt
+++ b/src/qt6ct-common/CMakeLists.txt
@@ -26,5 +26,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../)
 
 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 d97d4c7..1c8f10e 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
@@ -116,6 +120,9 @@ QStringList Qt6CT::sharedColorSchemePaths()
     for(const QString &p : QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation))
     {
         paths << (p + QLatin1String("/qt6ct/colors"));
+#if defined KF_CONFIGCORE_LIB && defined KF_COLORSCHEME_LIB
+        paths << (p + QLatin1String("/color-schemes"));
+#endif
     }
     paths << QLatin1String(QT6CT_DATADIR"/qt6ct/colors");
     paths.removeDuplicates();
@@ -124,6 +131,9 @@ QStringList Qt6CT::sharedColorSchemePaths()
 
 QString Qt6CT::resolvePath(const QString &path)
 {
+    if(path.isEmpty())
+        return path;
+
     QString tmp = path;
     tmp.replace("~", QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
     if(!tmp.contains("$"))
@@ -143,9 +153,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");
     QStringList activeColors = settings.value("active_colors").toStringList();
@@ -153,7 +175,6 @@ QPalette Qt6CT::loadColorScheme(const QString &filePath, const QPalette &fallbac
     QStringList disabledColors = settings.value("disabled_colors").toStringList();
     settings.endGroup();
 
-
 #if (QT_VERSION >= QT_VERSION_CHECK(6,6,0))
     if(activeColors.count() == QPalette::Accent)
         activeColors << activeColors.at(QPalette::Highlight);
@@ -163,24 +184,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 e01ddd2..c49c6b9 100644
--- a/src/qt6ct-common/qt6ct.h
+++ b/src/qt6ct-common/qt6ct.h
@@ -67,7 +67,8 @@ public:
     static QString userColorSchemePath();
     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 c3d7498..a4c1eaa 100644
--- a/src/qt6ct-qtplugin/CMakeLists.txt
+++ b/src/qt6ct-qtplugin/CMakeLists.txt
@@ -9,5 +9,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../)
 
 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 1d13faf..f9a209d 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, "applySettings", Qt::QueuedConnection);
-#ifdef QT_WIDGETS_LIB
         QMetaObject::invokeMethod(this, "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("qt6ct-style"))
         qCCritical(lqt6ct) << "unable to find qt6ct proxy style";
 #endif
+    QCoreApplication::instance()->installEventFilter(this);
 }
 
 Qt6CTPlatformTheme::~Qt6CTPlatformTheme()
@@ -92,7 +113,7 @@ QPlatformDialogHelper *Qt6CTPlatformTheme::createPlatformDialogHelper(DialogType
 
 const QPalette *Qt6CTPlatformTheme::palette(QPlatformTheme::Palette type) const
 {
-    return (m_usePalette && m_palette) ? m_palette.get() : QGenericUnixTheme::palette(type);
+    return m_palette ? &*m_palette : QGenericUnixTheme::palette(type);
 }
 
 const QFont *Qt6CTPlatformTheme::font(QPlatformTheme::Font type) const
@@ -146,46 +167,36 @@ 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)
     {
-        m_usePalette = false;
         m_update = true;
         return;
     }
 
-    if(!m_update)
-    {
-        //do not override application palette
-        if(QCoreApplication::testAttribute(Qt::AA_SetPalette))
-        {
-            m_usePalette = false;
-            qCDebug(lqt6ct) << "palette support is disabled";
-        }
-    }
-
-    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();
         }
 
-        if(!m_palette)
-            m_palette = std::make_unique<QPalette>(*QGenericUnixTheme::palette(QPlatformTheme::SystemPalette));
-
-        if(m_update && m_usePalette)
-            qApp->setPalette(*m_palette);
-
         if(m_userStyleSheet != m_prevStyleSheet)
         {
             // prepend our stylesheet to that of the application
@@ -207,25 +218,27 @@ void Qt6CTPlatformTheme::applySettings()
 #endif
 
     if(m_update)
-        QIconLoader::instance()->updateSystemTheme(); //apply icons
+    {
+        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(m_palette && m_usePalette)
-                w->setPalette(*m_palette);
-        }
+#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);
@@ -244,22 +257,17 @@ void Qt6CTPlatformTheme::updateSettings()
     readSettings();
     applySettings();
 }
-#endif
 
 void Qt6CTPlatformTheme::readSettings()
 {
-    m_palette.reset();
-
     QSettings settings(Qt6CT::configFile(), QSettings::IniFormat);
 
     settings.beginGroup("Appearance");
     m_style = settings.value("style", "Fusion").toString();
-    QString schemePath = settings.value("color_scheme_path").toString();
-    if(!schemePath.isEmpty() && settings.value("custom_palette", false).toBool())
-    {
-        schemePath = Qt6CT::resolvePath(schemePath); //replace environment variables
-        m_palette = std::make_unique<QPalette>(Qt6CT::loadColorScheme(schemePath, *QPlatformTheme::palette(SystemPalette)));
-    }
+    m_schemePath = !m_isIgnored && settings.value("custom_palette", false).toBool()
+        ? Qt6CT::resolvePath(settings.value("color_scheme_path").toString()) //replace environment variables
+        : QString();
+    m_palette = Qt6CT::loadColorScheme(m_schemePath);
     m_iconTheme = settings.value("icon_theme").toString();
     //load dialogs
     if(!m_update)
@@ -277,10 +285,10 @@ void Qt6CTPlatformTheme::readSettings()
     settings.endGroup();
 
     settings.beginGroup("Fonts");
-    m_generalFont = QGuiApplication::font();
-    m_generalFont.fromString(settings.value("general", QGuiApplication::font()).toString());
-    m_fixedFont = QGuiApplication::font();
-    m_fixedFont.fromString(settings.value("fixed", QGuiApplication::font()).toString());
+    m_generalFont = *QGenericUnixTheme::font(QPlatformTheme::SystemFont);
+    m_generalFont.fromString(settings.value("general").toString());
+    m_fixedFont = *QGenericUnixTheme::font(QPlatformTheme::FixedFont);
+    m_fixedFont.fromString(settings.value("fixed").toString());
     settings.endGroup();
 
     settings.beginGroup("Interface");
@@ -336,8 +344,6 @@ void Qt6CTPlatformTheme::readSettings()
             QCoreApplication::setAttribute(Qt::AA_ForceRasterWidgets, true);
         else if(!m_isIgnored && forceRasterWidgets == Qt::Unchecked)
             QCoreApplication::setAttribute(Qt::AA_ForceRasterWidgets, false);
-        if(m_isIgnored)
-            m_usePalette = false;
         settings.endGroup();
     }
 }
@@ -367,3 +373,17 @@ QString Qt6CTPlatformTheme::loadStyleSheets(const QStringList &paths)
     content.replace(regExp, "\n");
     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 6ad245b..50ca519 100644
--- a/src/qt6ct-qtplugin/qt6ctplatformtheme.h
+++ b/src/qt6ct-qtplugin/qt6ctplatformtheme.h
@@ -62,16 +62,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();
@@ -79,8 +82,8 @@ private:
     bool hasWidgets();
 #endif
     QString loadStyleSheets(const QStringList &paths);
-    QString m_style, m_iconTheme, m_userStyleSheet, m_prevStyleSheet;
-    std::unique_ptr<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;
@@ -88,7 +91,6 @@ private:
     int m_buttonBoxLayout;
     int m_keyboardScheme;
     bool m_update = false;
-    bool m_usePalette = true;
     int m_toolButtonStyle = Qt::ToolButtonFollowStyle;
     int m_wheelScrollLines = 3;
     bool m_showShortcutsInContextMenus = false;
diff --git a/src/qt6ct-style/CMakeLists.txt b/src/qt6ct-style/CMakeLists.txt
index ea8f426..cf64a58 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 fc154c2..cb4e477 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 "qt6ct.h"
 #include "appearancepage.h"
@@ -71,7 +74,7 @@ AppearancePage::AppearancePage(QWidget *parent) :
     QMenu *menu = new QMenu(this);
     menu->addAction(QIcon::fromTheme("document-new"), tr("Create"), this, SLOT(createColorScheme()));
     m_changeColorSchemeAction = menu->addAction(QIcon::fromTheme("accessories-text-editor"), tr("Edit"), this, SLOT(changeColorScheme()));
-    menu->addAction(QIcon::fromTheme("edit-copy"), tr("Create a Copy"), this, SLOT(copyColorScheme()));
+    m_copyColorSchemeAction = menu->addAction(QIcon::fromTheme("edit-copy"), tr("Create a Copy"), this, SLOT(copyColorScheme()));
     m_renameColorSchemeAction = menu->addAction(tr("Rename"), this, SLOT(renameColorScheme()));
     menu->addSeparator();
     m_removeColorSchemeAction = menu->addAction(QIcon::fromTheme("edit-delete"), tr("Remove"), this, SLOT(removeColorScheme()));
@@ -112,6 +115,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);
@@ -127,7 +139,7 @@ void AppearancePage::on_styleComboBox_textActivated(const QString &text)
 
 void AppearancePage::on_colorSchemeComboBox_activated(int)
 {
-    m_customPalette = Qt6CT::loadColorScheme(m_ui->colorSchemeComboBox->currentData().toString(), palette());
+    m_customPalette = Qt6CT::loadColorScheme(m_ui->colorSchemeComboBox->currentData().toString()).value_or(palette());
     updatePalette();
 }
 
@@ -303,6 +315,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())
     {
@@ -326,8 +339,7 @@ void AppearancePage::readSettings()
     m_ui->styleComboBox->setCurrentText(style);
 
     m_ui->customPaletteButton->setChecked(settings.value("custom_palette", false).toBool());
-    QString colorSchemePath = settings.value("color_scheme_path").toString();
-    colorSchemePath = Qt6CT::resolvePath(colorSchemePath); //replace environment variables
+    QString colorSchemePath = Qt6CT::resolvePath(settings.value("color_scheme_path").toString()); //replace environment variables
 
     QDir("/").mkpath(Qt6CT::userColorSchemePath());
     findColorSchemes(Qt6CT::userColorSchemePath());
@@ -342,7 +354,7 @@ void AppearancePage::readSettings()
         int index = m_ui->colorSchemeComboBox->findData(colorSchemePath);
         if(index >= 0)
             m_ui->colorSchemeComboBox->setCurrentIndex(index);
-        m_customPalette = Qt6CT::loadColorScheme(m_ui->colorSchemeComboBox->currentData().toString(), palette());
+        m_customPalette = Qt6CT::loadColorScheme(m_ui->colorSchemeComboBox->currentData().toString()).value_or(palette());
     }
 
     on_styleComboBox_textActivated(m_ui->styleComboBox->currentText());
@@ -381,11 +393,26 @@ void AppearancePage::findColorSchemes(const QString &path)
 {
     QDir dir(path);
     dir.setFilter(QDir::Files);
-    dir.setNameFilters(QStringList() << "*.conf");
+    QStringList nameFilters;
+    nameFilters << "*.conf";
+#if defined KF_CONFIGCORE_LIB && defined KF_COLORSCHEME_LIB
+    nameFilters << "*.colors";
+#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 a5c1a88..341365a 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);
@@ -72,7 +76,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 5113edd..419ac0a 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>
@@ -61,8 +62,8 @@ FontsPage::~FontsPage()
 void FontsPage::writeSettings(QSettings *settings)
 {
     settings->beginGroup("Fonts");
-    settings->setValue("general", m_ui->generalFontLabel->font().toString());
-    settings->setValue("fixed", m_ui->fixedFontLabel->font().toString());
+    settings->setValue("general", m_ui->generalFontLabel->property("value"));
+    settings->setValue("fixed", m_ui->fixedFontLabel->property("value"));
     settings->endGroup();
 }
 
@@ -70,11 +71,19 @@ void FontsPage::onFontChangeRequested(QWidget *widget)
 {
     bool ok = false;
     QFont font = QFontDialog::getFont (&ok, widget->font(), this);
-    if(ok)
-    {
-        widget->setFont(font);
-        qobject_cast<QLabel*>(widget)->setText(font.family () + " " + QString::number(font.pointSize ()));
-    }
+    if(!ok)
+        return;
+
+    if(font.weight() == QFont::Normal
+        && (font.styleName() == QLatin1String("Regular")
+            || font.styleName() == QLatin1String("Normal")
+            || font.styleName() == QLatin1String("Book")
+            || font.styleName() == QLatin1String("Roman")))
+        font.setStyleName(QString());
+
+    widget->setProperty("value", font.toString());
+    widget->setFont(font);
+    qobject_cast<QLabel*>(widget)->setText(font.family () + " " + QString::number(font.pointSize ()));
 }
 
 void FontsPage::readSettings()
@@ -88,10 +97,12 @@ 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"
+        ? QFontDatabase::systemFont(QFontDatabase::FixedFont)
+        : QFontDatabase::systemFont(QFontDatabase::GeneralFont)).value<QFont>();
     label->setText(font.family() + " " + QString::number(font.pointSize()));
     label->setFont(font);
+    label->setProperty("value", font.toString());
 }
 
 void FontsPage::on_createFontsConfButton_clicked()
diff --git a/src/qt6ct/iconthemepage.cpp b/src/qt6ct/iconthemepage.cpp
index 2f7621b..9f65c51 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", 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 e0131b5..8425a91 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 c389599..339d920 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 6008c97..c28820f 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