Qt,QML,ColorImage ไม่ใช่ประเภท

0

คำถาม

ฉันทำ 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
}

นี่คือว่ามันดูเป็นยังไงในคดีไซเนอร์: Here is how it looks in the designer

ใครช่วยคิดให้ออกทำไมมันถึงต้องบ่นตลอดว่า ColorImageไม่ใช่การเป็นประเภทเมื่อฉันพยายามที่จะเปิดตัว?

แก้ไข:

ที่นำเข้าเอกสารหรือที่อยู่เหนือแฟ้ม:

import QtQuick 2.15
import QtQuick.Controls 2.15
pyside2 qml qt
2021-11-14 14:36:50
1

คำตอบที่ดีที่สุด

2

ColorImage เป็น Qt ภายในส่วนประกอบส่วนตัว:

https://github.com/qt/qtdeclarative/blob/dev/src/quickcontrols2impl/qquickcolorimage.cpp

มันไม่เหมือนจะสนับสนุนสำหรับคนที่ไม่ใช่ภายในประโยชน์หรอก

ถ้าเธอต้องการจะใช้มันพยายาม import QtQuick.Controls.impl 2.15

โปรดสังเกตว่า ColorOverlay คืออีกครั้งที่มีอยู่ใน Qt 6.2 ใน Qt5Compat:

https://doc.qt.io/qt-6/qml-qt5compat-graphicaleffects-coloroverlay.html

มันจะถูกแทนที่ด้วย Qt เร็ว MultiEffect:

https://marketplace.qt.io/products/qt-quick-multieffect

2021-11-14 16:05:34

ขอบคุณเรื่องนี้ช่วยแก้ปัญหาของฉั!
Curtwagner1984

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................

ดังอยู่ในนี้หมวดหมู่

ดังคำถามอยู่ในนี้หมวดหมู่