Issue with KDE Adaptive Color Feature and Breeze Theme in PyQt5

I am currently developing a PyQt5 application that utilizes custom icons. However, I am facing challenges with the KDE Adaptive Color feature and the Breeze theme, as they seem to be ignoring color changes applied to my icons.

I have attempted to use QPalette in PyQt, but it does not allow me to retrieve the actual background color applied to my toolbar. Additionally, while I have been able to detect a color change via QEvent in my application, I am struggling to retrieve the specific background or text color in the toolbar.

To address this issue, I am seeking suggestions or approaches for:

  1. Obtaining the actual background color of my toolbar under KDE with the Adaptive Color feature enabled.
  2. Understanding how the KDE Adaptive Color feature and Breeze theme interact with color changes in PyQt5 applications.

Any help or suggestions would be greatly appreciated.

Mind sharing the source code of the project you’re working on to see what might be wrong?

Also, is the project using QtWidgets or QtQuick?

Hi,

Thank you for your response. I appreciate your willingness to help. My project primarily uses QtWidgets for the UI.

Regarding the source code, I can certainly share relevant portions that involve the toolbar, color changes, and icon customization. Here are snippets from the relevant sections:

import sys

from PyQt5.QtCore import QEvent
from PyQt5.QtGui import QIcon, QPalette
from PyQt5.QtWidgets import QApplication, QMainWindow, QToolBar, QAction


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.toolbar = QToolBar()
        self.addToolBar(self.toolbar)

        action = QAction("My Button", self)
        icon_path = "/home/noe/Bureau/my_icon.svg"
        icon = QIcon(icon_path)
        action.setIcon(QIcon(icon))
        self.toolbar.addAction(action)
        self.toolbar.setToolButtonStyle(2)

        self.current_palette = self.toolbar.palette()

    def print_palette(self):
        palette = self.toolbar.palette()

        print("Window :", palette.color(QPalette.Window).name())
        print("Window Background:", palette.color(QPalette.Background).name())
        print("WindowText:", palette.color(QPalette.WindowText).name())
        print("Button Background:", palette.color(QPalette.Button).name())
        print("ButtonText:", palette.color(QPalette.ButtonText).name())
        print("Highlight Background:", palette.color(QPalette.Highlight).name())
        print("HighlightText:", palette.color(QPalette.HighlightedText).name())
        print("Foreground:", palette.color(QPalette.Foreground).name())
        print("PlaceholderText:", palette.color(QPalette.PlaceholderText).name())
        print("Base:", palette.color(QPalette.Base).name())
        print("Text:", palette.color(QPalette.Text).name())
        print("BrightText:", palette.color(QPalette.BrightText).name())
        print("Light:", palette.color(QPalette.Light).name())
        print("Dark:", palette.color(QPalette.Dark).name())
        print("Shadow:", palette.color(QPalette.Shadow).name())
        print("BrightText:", palette.color(QPalette.BrightText).name())

    def event(self, event):
        if event.type() == QEvent.PaletteChange:
            self.update_colors()

        return super().event(event)

    def update_colors(self):
        print("update color")
        self.print_palette()


def main():
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec_())


if __name__ == "__main__":
    main()

Please let me know if you need more details or if there’s a specific aspect you’d like me to focus on. I’m eager to resolve this issue and any guidance you can provide would be immensely helpful.