Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to change palette from QSS stylesheet
QtWS25 Last Chance

How to change palette from QSS stylesheet

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.8k Views
  • 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 Offline
    K Offline
    Kobid
    wrote on last edited by
    #1

    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
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      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
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved