Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Change custom color themes at runtime
Forum Updated to NodeBB v4.3 + New Features

Change custom color themes at runtime

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 2.2k 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

    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"} }

    GrecKoG 1 Reply Last reply
    0
    • K Kobid

      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"} }

      GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

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

      K 1 Reply Last reply
      3
      • K Offline
        K Offline
        Kobid
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • GrecKoG GrecKo

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

          K Offline
          K Offline
          Kobid
          wrote on last edited by
          #4

          @GrecKo Yep, that works!

          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