Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    [Solved] QPalette and SystemPalette

    QML and Qt Quick
    2
    3
    1647
    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.
    • S
      svg_18 last edited by

      Hello,

      First of all, I am new to Qt/QML, so sorry if my post is confusing but I'm confused myself. I'll try to be specific.
      I have an app that uses C++/QML integration. I want my visual elements to have a consistent look, so I need to use SystemPalette. For example, if I have in qml:

      @SystemPalette {id: myPalette; colorGroup: SystemPalette.Active }@

      then for some text element I can do:

      @Text { id: myText; color: myPalette.text }@

      However, the default colors that I get from SystemPalette don't suit my needs.
      I read that you can set QPalette colors in the C++ code and then set the custom palette as app palette:

      @QPalette customPalette = myApp->palette();
      customPalette.setColor(QPalette::WindowText, QColor("red"));
      myApp->setPalette(customPalette);@

      but this had no effect for me and I don't see what I am missing here.

      My question: Is there a way to change the default SystemPalette colors? Or alternatively, how do I use my customPalette from qml?

      1 Reply Last reply Reply Quote 0
      • J
        Jens last edited by

        I haven't tried it but you are using the "WindowText" role on the C++ side and the "Text" role on the qml side. Perhaps you can simply change your C++ code to:
        @customPalette.setColor(QPalette::Text, QColor("red"));@

        1 Reply Last reply Reply Quote 0
        • S
          svg_18 last edited by

          I knew it was something that simple. Thanks for pointing it out!

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