脱,最大似然,ColorImage不是类型

0

的问题

我做了一个最大似然键成分和我用一个组成名 ColorImage 对标。 之后的寻找一种方法来变化图像的色彩。 我发现了脱不再支持 ColorOverlay

悬停,我只是输入在"颜色"在建设计工作室 ColorImage 弹出。 我试着找到文件的在线,但没有找到任何东西。 然而,当我决定试试,它只是作为我预期:

这是相关代码,从我的按钮:

    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
            }
        },

这全部门办法的图标和背景色的按钮。

这一工作在预览的建设计师。 然而,当我尝试运行它从Pyside,它告诉我: ColorImage is not a type 和根本没有载的按钮。

我试图找到相关文档 ColorImage 图找出可能有一个进口失踪。 然而,我不能把任何东西。 建设计的内部帮助没有把任何东西。 这是因为如果这件不存在。 但它不会和它的作品在设计工作室。

这里是全代码我按钮:

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是一夸脱内部的私人成分:

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

这似乎不是支持为非内部使用。

如果你真的想要使用它,试试 import QtQuick.Controls.impl 2.15

注意ColorOverlay可再脱6.2在Qt5Compat:

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

它最终将被替换为夸脱快速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ý
..................................................................................................................