Search code examples
c++qmlmaterial-designqt5.7qtquickcontrols2

QML Material Design colors aren't accurate


I'm trying to use the Purple and other colors specified on this page but the colors aren't displaying accurately.
This is the image of Purple color being displayed on my device as well as linux:

enter image description here

Here are the relevant code snippets from the default Hello World app:
.pro file:

QT += qml quick quickcontrols2

main.cpp:

#include <QQuickStyle>

In int main(int argc, char *argv[])
QQuickStyle::setStyle("Material");

main.qml:

Material.theme: Material.Dark
Material.accent: Material.Purple

Solution

  • The Material Design specs are a bit inconsistent about this. In the sticker sheet, all buttons are using such lighter shade in the dark theme, whereas elsewhere in the specs they are mostly using the same darker shade than in the light theme. We're considering switching it back, but meanwhile, here's a temporary workaround using Material.color():

    Material.theme: Material.Dark
    Material.accent: Material.color(Material.Purple)
    
    • QTBUG-54269: Material colors don't work as documented