Important: Please read the Qt Code of Conduct -

Change custom color themes at runtime

  • I'm using Material style in my app. I know how to switch between themes using qtquickcontrols2.conf file:


    But let say that I want to have predefined Material's themes like: pink, green, blue. Each one has own pedefined colors for Primary, Accent etc. User should be able to change between these themes at runtime (or at least after restart). How to do this? For example this works:

    ApplicationWindow {
        id: app
        visible: true
        Material.primary: "red"

    But this doesn't:
    RadioButton { text: qsTr("Red"); onClicked: {console.log("clicked"); Material.primary="red"} }

  • Qt Champions 2018

    The Material.primary="red" in the button's onClicked change the primary color of the button I believe.
    If you want to change it for all the descendants of your ApplicationWindow, you have to do app.Material.primary="red".
    Qt Quick Controls 2 styling gets inherited from the parent control.

  • This post is deleted!

  • @GrecKo Yep, that works!

Log in to reply