Material 主题似乎在 QML 中不起作用

问题描述 投票:0回答:2

我有一个简单的 QML,里面有一个

ApplicationWindow
RowLayout
和一堆
Buttons
。我已按照
the docs
应用了 Qt Quick Controls 2 Material 主题,但没有任何改变。怎么了?

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"
        }
    }
}
qt themes qml qtquickcontrols2
2个回答
12
投票

导入

QtQuick.Controls.Material 2.0
并设置某些材质特定属性不会应用材质主题。如果使用此处描述的方法之一设置主题,将使用它们:

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


0
投票

在main.cpp中添加QQuickStyle::setStyle("Material");

© www.soinside.com 2019 - 2024. All rights reserved.