Material theme doesn't seem to work in QML
 
我有一个简单的 QML,里面有一个 ApplicationWindow、RowLayout 和一堆 Buttons。我已经按照文档应用了 Qt Quick Controls 2 Material 主题,但没有任何改变。怎么了?
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 
 | import QtQuick 2.7import 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"
 }
 }
 }
 | 
		
		
- 你在 C 中使用 QQmlApplicationEngine 来加载 ApplicationWindow 吗?似乎需要从 QML 控制一些属性。请参阅 Qt 文档:doc.qt.io/qt-5/qtquickcontrols2-gettingstarted.html
 
	 
导入 QtQuick.Controls.Material 2.0 并设置一些特定于材质的属性不会应用材质主题。如果使用此处描述的方法之一设置主题,则将使用它们:
 
http://doc.qt.io/qt-5/qtquickcontrols2-styles.html
		
		
- 啊!谢谢你。太糟糕了,这不在我用作参考的页面上。 Qt 文档通常很好,但有时过于零散。
- 
顺便提一下,Qt Creator在导入QtQuick.Controls.Material的时候还是报错。此报告的错误是 Qt Creator 的一个已知错误,不应阻止应用样式。尝试加载 TextEditor 示例。它使用 QtQuick Controls 2 并在 Qt Creator 中显示错误,尽管它正确使用了 qtquickcontrols2.conf [Material] 部分参数。请参阅 bugreports.qt.io/browse/QTBUG-54986 和 doc.qt.io/qt-5/qtquickcontrols2-texteditor-example.html。我正在使用 Qt Creator 4.4.0 和 Qt 5.9.1。