Eu fiz um software livre componente de botão e eu usei um componente chamado ColorImage
para o ícone. Depois de procurar por uma maneira de alterar as cores da imagem. Eu descobri que o Qt não suportam mais ColorOverlay
Passe, eu digitei no " cor " no Qt Estúdio de Design e ColorImage
apareceu. Eu tentei encontrar a documentação on-line, mas não consegui encontrar nada. No entanto, quando eu decidi experimentá-lo, ele só funciona como esperado:
Este é o código do meu botão:
contentItem: ColorImage {
id: buttonIcon
source: imageSource
fillMode: Image.PreserveAspectFit
height: parent.height
color: iconColor
anchors.fill: actionBarButton
anchors.margins: 4
}
Quando o hovered
estado do botão torna-se true
permite a seguinte estado:
State {
when: (hovered && !checked)
name: "hoveredNotChecked"
PropertyChanges {
target: buttonIcon
color: "white"
}
PropertyChanges {
target: buttonBackground
color: iconColor
}
},
que troca o ícone e a cor de fundo do botão.
Isso funciona na visualização do Qt Designer. No entanto, quando tento executá-lo a partir de Pyside, ele me diz: ColorImage is not a type
e simplesmente não consegue carregar o botão.
Eu tentei encontrar documentação sobre ColorImage
para descobrir talvez haja uma importação em falta. No entanto, eu não podia virar nada. O Qt Designer interna não apareceu nada bem. É como se este componente não existe. Mas ele faz, e ele trabalha em um Estúdio de Design.
Aqui está o código completo para o meu botão:
Button {
id: actionBarButton
property color iconColor: "red"
property color backgroundColor: "blue"
property string toolTipText: "Play video!"
property string imageSource: "images/round_play_arrow_white_36dp.png"
property string imageSourceChecked: "images/round_play_arrow_white_36dp.png"
states: [
State {
when: (hovered && !checked)
name: "hoveredNotChecked"
PropertyChanges {
target: buttonIcon
color: "white"
}
PropertyChanges {
target: buttonBackground
color: iconColor
}
},
State {
when: (hovered && checked)
name: "hoveredChecked"
PropertyChanges {
target: buttonIcon
source: imageSourceChecked
color: "white"
}
PropertyChanges {
target: buttonBackground
color: iconColor
}
},
State {
when: checked
name: "checked"
PropertyChanges {
target: buttonIcon
source: imageSourceChecked
}
}
]
transitions: Transition {
ColorAnimation {
duration: 300
}
}
contentItem: ColorImage {
id: buttonIcon
source: imageSource
fillMode: Image.PreserveAspectFit
height: parent.height
color: iconColor
anchors.fill: actionBarButton
anchors.margins: 4
}
onHoveredChanged: {
}
background: Rectangle {
id: buttonBackground
color: backgroundColor
anchors.fill: actionBarButton
}
ToolTip.delay: 1000
ToolTip.timeout: 5000
ToolTip.visible: hovered
ToolTip.text: actionBarButton.toolTipText
}
Esta é a forma como ele olha no designer:
Alguém pode me ajudar a descobrir por que ele reclama de ColorImage
não sendo um tipo quando eu tento iniciar?
Editar:
As importações no arquivo acima:
import QtQuick 2.15
import QtQuick.Controls 2.15