Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    How to change palette from QSS stylesheet

    General and Desktop
    2
    2
    3479
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      Kobid last edited by

      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

      1 Reply Last reply Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by Chris Kawa

        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.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post