ฉันทำ QML ปุ่มส่วนประกอบและฉันเคยเป็นส่วนประกอบที่ชื่อ ColorImage
สำหรับไอคอน หลังจากค้นหาหนทางที่จะเปลี่ยนสีของภาพ. ฉันรู้ว่า Qt ไม่สนับสนุน ColorOverlay
เมาส์อยู่เหนือผมแค่ป้อนไว้ใน'สีในการออกแบบ Qt สตูดิโอแล้ว ColorImage
มือนผุดขึ้นมากขึ้น ฉันพยายามค้นหาเอกสารออนไลน์แต่ยังไม่สามารถ\n หาสิ่งต่างๆได้ อย่างไรก็ตามเมื่อฉันตัดสินใจที่จะลองมันมันแค่ทำงานอย่างที่ฉันคาดหวัง:
นี่คือคนที่เกี่ยวข้องรหัสออกจากปุ่ม:
contentItem: ColorImage {
id: buttonIcon
source: imageSource
fillMode: Image.PreserveAspectFit
height: parent.height
color: iconColor
anchors.fill: actionBarButton
anchors.margins: 4
}
ตอนที่ hovered
รัฐจากที่ปุ่มกลายเป็น true
มันเปิดใช้การติดตามสถานะ:
State {
when: (hovered && !checked)
name: "hoveredNotChecked"
PropertyChanges {
target: buttonIcon
color: "white"
}
PropertyChanges {
target: buttonBackground
color: iconColor
}
},
ซึ่ง swaps องภาพไอคอนและเบื้องหลังสีบนปุ่ม
มันทำงานในพื้นที่แสดงภาพตัวอย่างของ Qt ดีไซเนอร์ อย่างไรก็ตามตอนที่ฉันพยายามจะหนีมันออกมาจาก Pyside มันบอกฉันว่า: ColorImage is not a type
และเพียงล้มเหลวที่จะโหลดปุ่มนั่น
ฉันพยายามหาเรื่องเอกสารคู่มือ@info:shell ColorImage
ที่จะคิดออกมาบางทีอาจมีการนำเข้าหายตัวไป อย่างไรก็ตามฉันไม่สามารถเปลี่ยนอะไรเลย Qt designer นภายในช่วยไม่ได้เปลี่ยนเป็นอะไรเช่นกัน มันเป็นเหมือนว่านี่ส่วนประกอบไม่มีอยู่จริง แต่มันและมันทำงานการออกแบบที่สตูดิโอ
นี่คือเต็มไปด้วยรหัสสำหรับปุ่ม:
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
}
นี่คือว่ามันดูเป็นยังไงในคดีไซเนอร์:
ใครช่วยคิดให้ออกทำไมมันถึงต้องบ่นตลอดว่า ColorImage
ไม่ใช่การเป็นประเภทเมื่อฉันพยายามที่จะเปิดตัว?
แก้ไข:
ที่นำเข้าเอกสารหรือที่อยู่เหนือแฟ้ม:
import QtQuick 2.15
import QtQuick.Controls 2.15