[Solved] QPalette and SystemPalette



  • 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?



  • 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"));@



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.