Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to change palette from QSS stylesheet



  • Hi,

    I have this code:
    @ QApplication::setStyle(QStyleFactory::create("Fusion"));
    QPalette p = qApp->palette();
    p.setColor(QPalette::Window, QColor(53,53,53));
    p.setColor(QPalette::Button, QColor(53,53,53));
    p.setColor(QPalette::Highlight, QColor(175,0,0));
    p.setColor(QPalette::ButtonText, QColor(255,255,255));
    p.setColor(QPalette::WindowText, QColor(255,255,255));
    qApp->setPalette(p);@

    Can I do this same but from QSS? I just want move this harcoded runtime style definition to the QSS so user can modify it. I googled how to read palette by paletterole but how to write?

    Regards


  • Moderators

    AFAIK you can't. Palettes are "weaker" then QSS or native styling and are overridden by both of them. Therefore think of QSS as a replacement for palettes, not an interface to them.

    But you can move palette settings to a file just as well as QSS. You can store the RGB values in whatever format - ini, json, xml or even something as trivial as

    window 53 53 53
    button 53 53 53
    ...
    

    and read them at runtime.


Log in to reply