8

I have a simple QML with an ApplicationWindow, RowLayout and a bunch of Buttons inside. I have applied the Qt Quick Controls 2 Material theme as per the docs, but nothing changed. What's wrong?

import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Controls.Material 2.0
import QtQuick.Layouts 1.3

ApplicationWindow {
    Material.theme: Material.Dark
    Material.accent: Material.Orange

    id: window
    visible: true

    RowLayout {
        anchors.horizontalCenter: window.horizontalCenter
        anchors.bottomMargin: 32

        Button {
            text: "A"
        }

        Button {
            text: "B"
        }

        Button {
            text: "C"
        }
    }
}
jpnurmi
  • 5,716
  • 2
  • 21
  • 37
Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335
  • Do you use `QQmlApplicationEngine` in C++ to load the `ApplicationWindow`? It seems it is needed to control some properties from QML. See Qt documentation: http://doc.qt.io/qt-5/qtquickcontrols2-gettingstarted.html – Benjamin T Aug 03 '16 at 09:43

1 Answers1

12

Importing QtQuick.Controls.Material 2.0 and setting some Material specific properties do not apply the Material theme. They will be used if the theme is set using one of the methods described here:

http://doc.qt.io/qt-5/qtquickcontrols2-styles.html

  • Ah! Thank you. Too bad this isn't on the page I used for reference. Qt documentation is generally good, but sometimes too fragmented. – Violet Giraffe Aug 03 '16 at 10:32
  • Let me mention that there's still an error reported by Qt Creator when importing `QtQuick.Controls.Material`. This reported error is a known bug of Qt Creator and should not prevent the style from being applied. Try loading the TextEditor example. It uses QtQuick Controls 2 and shows the error in Qt Creator although it correctly uses the `qtquickcontrols2.conf` `[Material]` section parameters. See https://bugreports.qt.io/browse/QTBUG-54986 and https://doc.qt.io/qt-5/qtquickcontrols2-texteditor-example.html . I'm using Qt Creator 4.4.0 and Qt 5.9.1. – SR_ Sep 16 '17 at 08:58