代码之家  ›  专栏  ›  技术社区  ›  Luca

qml change按钮foregrouns color with Qt controls 2.0

  •  0
  • Luca  · 技术社区  · 8 年前

    我正在尝试使用 QtQuick.Controls 2.0

     Button {
            id: testButton
            width: 80
            height: 30
            enabled: false
            text: "Test"
    
            background: Rectangle {
                color: testButton.enabled ? "steelblue" : "gray"
            }
        }
    

    这是可行的,但我已经梳理了这里的要点( https://doc.qt.io/qt-5/qml-qtquick-controls2-button-members.html

    1 回复  |  直到 8 年前
        1
  •  1
  •   dtech    8 年前

    控件2实际上并不打算按每个对象设置样式。它们与 available GUI styles 因此,在不同组件之间提供统一的视觉风格。

    Material.foreground: Material.Red // globally
    // or
    Button {
        Material.foreground: Material.Red // per object
    }
    

    默认样式没有选项,它是简单明了的黑白样式,以获得最佳性能。通用样式使您能够设置背景色、前景色和强调色,材质样式也为您提供了额外的主色。

    看见 here 了解更多详细信息。