Search code examples
qtqmlqt5qtquick2qtquickcontrols2

How do I create a custom QML Control that respects the Material Style colors?


I am creating a custom Control in QML for my application. I want to run on both desktop and Android, so I'm using Material Style for the application. This applies a colour scheme to all existing Qt Quick Controls 2 controls (buttons, toolbars, etc). But how do I use those colours on my control? I know I can just use the same colours with a hex code or whatever, but I want my control's colours to change if I change the accent colour in the theme, etc.

I've tried SystemPalette but the colours there don't seem to follow Material Style but rather always follow the default style.

Is it possible for me to get access to the Material colours? What will happen if the application is run in non-Material mode?


Solution

  • Just figured it out. Set an id on any actual control, then you can access the "extra" colours as controlId.Material.buttonColor etc