Qt 5.7: Material.accent not working

  • Hi; My basic code is here:

    ApplicationWindow {
      visible: true
      width: 300
      height: 300
      title: qsTr("Hello World")
      Material.theme: Material.Dark
      Material.accent: Material.Purple
      header: ToolBar {
        id: toolBar
        Material.accent: Material.Amber
        RowLayout {
          anchors.fill: parent
          ToolButton {
            text: qsTr("\u25C0 %1").arg(Qt.application.name)

    When I ran this app, I see ToolBar color is blue:
    ToolBar Color
    I tried Material.accent: Material.color(Material.Amber) and Material.background: Material.Amber but not working, always toolbar color is blue. How can I set it? Thanks.

  • Qt Champions 2016

    @Ibrahim in qml you have imported QtQuick.Controls.Material 2.0 ?
    and you have configured Material style ? per ex in main.cpp:
    qputenv("QT_QUICK_CONTROLS_STYLE", "material");

  • @ekkescorner thanks. Yes, I imported QtQuick.Controls.Material 2.0 and I set QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); qputenv("QT_QUICK_CONTROLS_STYLE", "material"); in main.cpp.
    But it's not working with Material.accent. I tried Material.primary: Material.Amber and it's working well.
    Actually I don't understand, what is difference between Material.accent and Material.primary and Material.background?

  • Qt Champions 2016

    @Ibrahim you should study https://material.google.com/style/color.html# to see where accent is used and where primary is used
    and the Material.background is normaly set by Qt Quick Controls 2 and depends from Theme.
    you can overwrite the background - see here: https://doc-snapshots.qt.io/qt5-5.8/qtquickcontrols2-material.html#material-background-attached-prop

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.