Ho fatto un QML componente pulsante e ho usato un componente denominato ColorImage
per l'icona. Dopo la ricerca di un modo per cambiare il colore dell'immagine. Ho scoperto che Qt non supportano più ColorOverlay
Hover, ho scritto nel "colore" in Qt e Studio di Progettazione ColorImage
spuntato. Ho provato a trovare la documentazione online, ma non ho trovato nulla. Tuttavia, quando ho deciso di provare, funziona come mi aspettavo:
Questo è il codice in questione dal mio pulsante:
contentItem: ColorImage {
id: buttonIcon
source: imageSource
fillMode: Image.PreserveAspectFit
height: parent.height
color: iconColor
anchors.fill: actionBarButton
anchors.margins: 4
}
Quando il hovered
stato del pulsante diventa true
permette la seguente stato:
State {
when: (hovered && !checked)
name: "hoveredNotChecked"
PropertyChanges {
target: buttonIcon
color: "white"
}
PropertyChanges {
target: buttonBackground
color: iconColor
}
},
riporti, l'icona e il colore di sfondo del pulsante.
Questo funziona in anteprima il Qt Designer. Tuttavia, quando si tenta di eseguire da Pyside, mi dice: ColorImage is not a type
e semplicemente non riesce a caricare il pulsante.
Ho provato a trovare la documentazione di ColorImage
per capire che forse c'è un'importazione mancanti. Tuttavia, non potevo far nulla. Qt Designer di interni di aiuto non tutto come bene. È come se questo componente non esiste. Ma lo fa, e funziona in Studio di Design.
Ecco il codice completo per il mio pulsante:
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
}
Questo è come appare nella finestra di progettazione:
Qualcuno mi può aiutare a capire perché si lamenta ColorImage
non essendo un tipo quando provo a lanciare?
Edit:
Le importazioni nel file di cui sopra:
import QtQuick 2.15
import QtQuick.Controls 2.15