First step would be to remove the MouseArea completely. Then, use the "hovered"
property that Button inherits from Control:
Material.foreground: btnOK.hovered ? Material.Red : Material.Grey
(Untested)
> -----Original Message-----
> From: Interest <[email protected]> On Behalf Of
> Minzhang He
> Sent: Wednesday, 21 November 2018 2:46 AM
> To: [email protected]
> Subject: [Interest] How to change button color in QML?
>
> I just started using and like QtQuick.Controls 2.
>
> I want change button Material color in QML.
> this is my QML code:
> Button {
> id: btnOK
> x: 248
> y: 208
> text: qsTr("确认")
> Material.foreground: Material.primary
> Material.background: Material.Dark
> MouseArea{
> anchors.fill: parent
> hoverEnabled: true
> onEntered: {
> //this is want to change Material code:
> //btnOK.Material.foreground = ???
> //btnOK.Material.background = ???
> }
> }
> }
> Can you help me?
_______________________________________________
Interest mailing list
[email protected]
https://lists.qt-project.org/listinfo/interest