Urobil som PROGRAM na tlačidlo komponent a som použil komponent s názvom ColorImage
pre ikonu. Po hľadajú spôsob, ako zmeniť obrázok farba. Zistil som, že Qt už podporu ColorOverlay
Vznášať sa, len som napísal v "farba" v Qt Design Studio a ColorImage
vyskočila. Snažil som sa nájsť v dokumentácii on-line, ale nemohol nájsť nič. Avšak, keď som sa rozhodol to skúsiť, to proste funguje ako som čakal, že:
Toto je príslušný kód z môjho tlačidlo:
contentItem: ColorImage {
id: buttonIcon
source: imageSource
fillMode: Image.PreserveAspectFit
height: parent.height
color: iconColor
anchors.fill: actionBarButton
anchors.margins: 4
}
Keď hovered
štát od tlačidlo stáva true
to umožňuje nasledujúce štát:
State {
when: (hovered && !checked)
name: "hoveredNotChecked"
PropertyChanges {
target: buttonIcon
color: "white"
}
PropertyChanges {
target: buttonBackground
color: iconColor
}
},
ktoré swapy na ikonu a farbu pozadia na tlačidlo.
Funguje to v ukážky Qt Designer. Avšak, keď sa pokúsim spustiť z Pyside, to mi hovorí: ColorImage is not a type
a jednoducho nepodarí načítať tlačidlo.
Snažil som sa nájsť dokumentáciu o ColorImage
ak chcete zistiť, možná je import chýba. Avšak, nemohol som zase nič. Qt Designer je vnútorný pomôcť si nie je zase až niečo ako dobre. To je ako keby táto zložka neexistuje. Ale to, a funguje to v Design Studio.
Tu je plný kód pre moje tlačidlo:
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
}
Môže mi niekto pomôcť zistiť, prečo sa vypíše st 'ažnost' o ColorImage
nie je typ, pri pokuse o spustenie?
Úprava:
Dovoz v súbore vyššie:
import QtQuick 2.15
import QtQuick.Controls 2.15