Discussion:
[Interest] How to change button color in QML?
Minzhang He
2018-11-21 01:45:44 UTC
Permalink
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?
Mitch Curtis
2018-11-26 14:17:08 UTC
Permalink
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 <interest-***@lists.qt-project.org> On Behalf Of
> Minzhang He
> Sent: Wednesday, 21 November 2018 2:46 AM
> To: ***@qt-project.org
> 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?
He Minzhang
2018-11-27 15:49:34 UTC
Permalink
thanks a million.

»ñÈ¡ Outlook for Android<https://aka.ms/ghei36>

________________________________
From: Mitch Curtis <***@qt.io>
Sent: Monday, November 26, 2018 10:17:08 PM
To: Minzhang He; ***@qt-project.org
Subject: RE: [Interest] How to change button color in QML?

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 <interest-***@lists.qt-project.org> On Behalf Of
> Minzhang He
> Sent: Wednesday, 21 November 2018 2:46 AM
> To: ***@qt-project.org
> 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?
Loading...