Solved QML button's palette with enabled property
-
Hello
I am using the raw of buttons to perform some actions and at the same time to represent the current state of the project. So I use
palette.button
to set the current color. When the button has been clicked by the user it should go to disabled state for the action running time. So I doenabled = false
. All works as expected except that the button visually stays in the disabled state (text is faded) even after I re-enable it (enabled = true
) though it is, in fact, active now (I can click on it and the action will propagate). It seems like non-default palettes aren't compatible withenabled
property. Is it a known behavior or I'm missing something?I am using PySide2. QML imports are:
import QtQuick 2.12 import QtQuick.Controls 2.12 import QtQuick.Layouts 1.12 import QtGraphicalEffects 1.12 import QtQuick.Dialogs 1.3 as QtDialogs import Qt.labs.platform 1.1 as QtLabs import ProjectListItem 1.0 import Settings 1.0
-
OK, I guess I should just set
buttonText
property explicitly when manipulating button's palette so the text always will be in the desired state. Not very elegant but anyway... Probably can useState
component to group both changes in background and text under one thing. -
I don't know. But: https://doc.qt.io/qt-5/qpalette.html#ColorRole-enum gives... something.
But also, if you dig into source you could probably know what you are looking to seek (I don't know exactly your situation but you can find out).I.e. for me ( QML ) I'd start digging and find out how things are, places things like:
"\Qt<version><kit>\qml\QtQuick\Controls.2\Button.qml" for example:background: Rectangle { implicitWidth: 100 implicitHeight: 40 visible: !control.flat || control.down || control.checked || control.highlighted color: Color.blend(control.checked || control.highlighted ? control.palette.dark : control.palette.button, control.palette.mid, control.down ? 0.5 : 0.0) border.color: control.palette.highlight border.width: control.visualFocus ? 2 : 0 }
and if I'd used Material theme see@ "\Qt<version><kit>\qml\QtQuick\Controls.2\Material\Button.qml" for example:
color: !control.enabled ? control.Material.buttonDisabledColor : control.highlighted ? control.Material.highlightedButtonColor : control.Material.buttonColor
Anyhow, point is, you might find just a theme might do it - possibly not. In which case, you can always overwrite the background delegate for fine tuning yourself. Or any other section that doesn't quite do it for you.
-
OK, I guess I should just set
buttonText
property explicitly when manipulating button's palette so the text always will be in the desired state. Not very elegant but anyway... Probably can useState
component to group both changes in background and text under one thing.