Ok. This is a minimal sample code of the problem.
If I specify any color for “item1″‘s icon when the MenuItem is disabled the icon won’t gray out.
So the question is if this is a QML bug or There is a way to evade the problem.
I have to use the transparent color because otherwise the icon(Which contains transparent pixels) will turn black.
import QtQuick 6.5
import QtQuick.Controls 6.5
import UntitledProject2
Rectangle {
id: rectangle
width: 200
height: 200
state: "State1"
Menu {
id: menu
title: "Menu"
MenuItem {
id: item1
text: "Item 1"
icon {
source: "images/cam1.png"
// The issue is here. removing this line will give the disabled effect on icon.
color: "transparent"
}
}
}
Button {
id: button
text: qsTr("Press me")
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
Connections {
target: button
onClicked: menu.open()
}
}
Button {
id: stateButton
text: qsTr("Change state")
anchors.verticalCenter: parent.verticalCenter
anchors.verticalCenterOffset: 45
anchors.horizontalCenter: parent.horizontalCenter
Connections {
target: rectangle
onClicked: {
if (rectangle.state === "State2")
rectangle.state = "State1"
else
rectangle.state = "State2"
}
}
}
states: [
State {
name: "State1"
PropertyChanges {
target: item1
enabled: false
}
PropertyChanges {
target: subMenu
enabled: false
}
},
State {
name: "State2"
}
]
}
I tried changing color when changing state to values other than “transparent” hoping the problem is with transparent value. But I found out specifying any color would cause the icon to not have disabled effect.