首页 > 解决方案 > 未找到状态和绑定资源

问题描述

在我的应用程序中,我需要跟踪按钮的状态并更改它的图标。在 Visual Studio 中一切正常,但在 buildMashine 状态下未找到资源且图标未显示,我也尝试使用 Binding,但无法正常工作。

RowLayout {
    id: chatFileDeledate  

    property int stateFile:  model.fileState


    ToolButton {
        id: btnFileDownload
        width: 40
        height: width

        Rectangle {
            id: rectOverlay
            Image {
                id: imageIcon
                width: 30
                height: width
                anchors.centerIn: parent
                fillMode: Image.Stretch
                sourceSize.width: width
                sourceSize.height: height
            }
        }
    }

    states: [
        State {
            when: stateFile == VSQmlChatTypes.NeedDownload
            PropertyChanges { target: imageIcon; source: "qrc:/img/icons/file_transfer_download.svg"; }
        },
        State {
            when: stateFile == VSQmlChatTypes.IsDownloading
            PropertyChanges { target: imageIcon; source: "qrc:/img/icons/file_transfer_stop.svg"; }         //process download
        },
        State {
            when: stateFile == VSQmlChatTypes.DownloadSuccessful
            PropertyChanges { target: imageIcon; source: "qrc:/img/icons/file_transfer_open.svg"; }
        },
        State {
            when: stateFile == VSQmlChatTypes.StopDownload
            PropertyChanges { target: imageIcon; source: "qrc:/img/icons/file_transfer_error.svg"; }
        }
    ]
}

但如果我做到了

Image {
    id: imageIcon
    width: 30
    height: width
    anchors.centerIn: parent
    fillMode: Image.Stretch
    sourceSize.width: width
    sourceSize.height: height
    source: "qrc:/img/icons/file_transfer_download.svg"
 }

并显示删除状态图标

标签: qtqml

解决方案


推荐阅读