Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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:

    [Controls]
    Style=Material
    
    [Universal]
    Theme=Dark
    Accent=Red
    
    [Material]
    Theme=Dark
    Primary=Gray
    Accent=#825AA7
    

    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

    @Kobid
    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