Bir QML düğmesi bileşeni yaptım ve adında bir bileşen kullandım ColorImage
simge için. Görüntü rengini değiştirmenin bir yolunu aradıktan sonra. Qt'nin artık coloroverlay'i desteklemediğini öğrendim
Hover, Qt Design Studio'da 'renk' yazdım ve ColorImage
attı. İnternette dokümantasyon bulmaya çalıştım ama hiçbir şey bulamadım. Ancak, denemeye karar verdiğimde, beklediğim gibi çalışıyor:
Bu benim düğmemdeki ilgili kod:
contentItem: ColorImage {
id: buttonIcon
source: imageSource
fillMode: Image.PreserveAspectFit
height: parent.height
color: iconColor
anchors.fill: actionBarButton
anchors.margins: 4
}
Ne zaman hovered
düğmeden durum olur true
aşağıdaki durumu etkinleştirir:
State {
when: (hovered && !checked)
name: "hoveredNotChecked"
PropertyChanges {
target: buttonIcon
color: "white"
}
PropertyChanges {
target: buttonBackground
color: iconColor
}
},
düğmedeki simgeyi ve arka plan rengini değiştirir.
Bu, Qt Tasarımcısının önizlemesinde çalışır. Ancak, onu Pyside'dan çalıştırmaya çalıştığımda, bana: ColorImage is not a type
ve sadece düğmeyi yüklemek için başarısız olur.
Hakkında belgeler bulmaya çalıştım. ColorImage
belki bir ithalatın eksik olduğunu anlamak için. Ancak, hiçbir şey bulamadım. Qt Designer'ın dahili yardımı da hiçbir şey ortaya çıkarmadı. Sanki bu bileşen yokmuş gibi. Ama öyle ve Tasarım Stüdyosunda çalışıyor.
İşte düğmem için tam kod:
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
}
Biri şikayet hakkında onu bunu anlamam için bana yardımcı olabilir ColorImage
fırlatmaya çalıştığımda tiplik yapmıyor muyum?
Düzenlemek:
Yukarıdaki dosyadaki içe aktarmalar:
import QtQuick 2.15
import QtQuick.Controls 2.15