Qml 房地产市场不会着火

Qml 房地产市场不会着火,qml,Qml,我有QML元素,其中包含透明的矩形和图像。此元素的目的是显示某些操作成功-如果某些操作成功执行,则会弹出,然后在1000ms的时间内缓慢消失 以下是完成此工作的简化代码: import QtQuick 2.5 import QtQuick.Layouts 1.1 Rectangle { id: ueActionResultIndicator property bool ueParamConnectionOk: false width: 128 height:

我有
QML
元素,其中包含透明的
矩形
图像
。此元素的目的是显示某些操作成功-如果某些操作成功执行,则会弹出,然后在1000ms的时间内缓慢消失
以下是完成此工作的简化代码:

import QtQuick 2.5
import QtQuick.Layouts 1.1

Rectangle
{
    id: ueActionResultIndicator

    property bool ueParamConnectionOk: false

    width: 128
    height: 128

    color: "transparent"

    ColumnLayout
    {
        anchors.fill: parent


        Image
        {
            Layout.fillWidth: true
            Layout.fillHeight: true

            horizontalAlignment: Qt.AlignHCenter
            verticalAlignment: Qt.AlignVCenter

            smooth: true

            fillMode: Image.PreserveAspectFit

//            source: ueParamConnectionOk===true?"qrc:///ueIcons/icons/ueActionOk.png"
//                                              :"qrc:///ueIcons/icons/ueActionCancel.png"
            source: "http://www.clker.com/cliparts/0/f/7/0/11954234311954389563ok_mark_h_kon_l_vdal_02.svg.hi.png"
        }   // Image
    }   // ColumnLayout

    states:
    [
        State
        {
            name: "ueStateHidden"

            PropertyChanges
            {
                target: ueActionResultIndicator

                opacity: 0.00
            }   // PropertyChanges
        },  // State

        State
        {
            name: "ueStateShown"

            PropertyChanges
            {
                target: ueActionResultIndicator

                opacity: 1.00
            }   // PropertyChanges
        }   // State
    ]   // states

    transitions:
    [
        Transition
        {
            from: "ueStateShown"
            to: "ueStateHidden"

            PropertyAnimation
            {
                properties: "opacity"

                duration: 1000

                loops: 3

                easing.type: Easing.InOutSine

                onStarted:
                {
                    visible=true;
                    enabled=true;
                }   // onStarted

                onStopped:
                {
                    visible=false;
                    enabled=false;
                }   // onStopped
            }   // PropertyAnimation
        }   // Transition
    ]   // transitions

    Component.onCompleted:
    {
        state="ueStateHidden";
    }   // Component.onCompleted
}   // Rectangle
下面是触发它的
.QML
文件

import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.1
import QtQuick.Window 2.2
import QtQuick.Controls.Styles 1.4

Window
{
    width: 512
    height: 512

    flags: Qt.FramelessWindowHint

    visible: true

    ColumnLayout
    {
        anchors.fill: parent

        spacing: 8

        Rectangle
        {
            Layout.fillWidth: true
            Layout.fillHeight: true
            Layout.margins: 8

            radius: 16
            border.color: "#4682b4"
            border.width: 1
            antialiasing: true

            gradient: Gradient
            {
                GradientStop
                {
                    position: 0
                    color: "#636363"
                }   // GradientStop

                GradientStop
                {
                    position: 1
                    color: "#303030"
                }   // GradientStop
            }   // Gradient

            ColumnLayout
            {
                anchors.fill: parent

                RowLayout
                {
                    spacing: 8
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    Layout.margins: 8
                    Layout.alignment: Qt.AlignHCenter|Qt.AlignTop

                    antialiasing: true

                    Text
                    {
                        text: qsTr("APPLICATION SETTINGS")
                        clip: true
                        font.bold: true
                        font.pointSize: 24
                        textFormat: Text.RichText
                        verticalAlignment: Text.AlignVCenter
                        horizontalAlignment: Text.AlignHCenter
                    }   // Text
                }   // RowLayout

                ColumnLayout
                {
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    Layout.margins: 8
                    Layout.alignment: Qt.AlignHCenter|Qt.AlignBottom

                    TabView
                    {
                        Layout.fillWidth: true
                        Layout.fillHeight: true
                        Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter

                        frameVisible: true

                        Tab
                        {
                            asynchronous: true
                            title: qsTr("Database")

                            Layout.fillWidth: true
                            Layout.fillHeight: true
                            Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter

                            ColumnLayout
                            {
                                spacing: 8
                                Layout.fillWidth: true
                                Layout.fillHeight: true
                                Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter

                                TextField
                                {
                                    id: textFieldServerAddress
                                    antialiasing: true

                                    Layout.fillWidth: true
                                    Layout.fillHeight: false

                                    placeholderText: qsTr("database server address")
                                }   // TextField

                                TextField
                                {
                                    id: textFieldServerPort

                                    Layout.fillWidth: true
                                    Layout.fillHeight: false

                                    placeholderText: qsTr("database server port")
                                }   // TextField

                                TextField
                                {
                                    id: textFieldDatabaseName

                                    Layout.fillWidth: true
                                    Layout.fillHeight: false

                                    placeholderText: qsTr("database name")
                                }   // TextField

                                TextField
                                {
                                    id: textFieldDatabaseUsername

                                    Layout.fillWidth: true
                                    Layout.fillHeight: false

                                    placeholderText: qsTr("database access username")
                                }   // TextField

                                TextField
                                {
                                    id: textFieldDatabasePassword

                                    Layout.fillWidth: true
                                    Layout.fillHeight: false

                                    placeholderText: qsTr("database access password")

                                    echoMode: TextInput.PasswordEchoOnEdit
                                }   // TextField

                                RowLayout
                                {
                                    Layout.fillWidth: true
                                    Layout.fillHeight: false
                                    Layout.alignment: Qt.AlignLeft|Qt.AlignVCenter
                                    spacing: 8

                                    Button
                                    {
                                        Layout.fillWidth: false
                                        Layout.fillHeight: true
                                        Layout.alignment: Qt.AlignLeft|Qt.AlignVCenter

                                        text: qsTr("Test Connection")

                                        onClicked:
                                        {
                                            ueActionResultIndicator.state="ueStateShown";
                                        }   // onClicked
                                    }   // Button
                                }   // RowLayout
                            }   // ColumnLayout
                        }   // Tab
                    }   // TabView
                }   // ColumnLayout
            }   // ColumnLayout
        }   // Rectangle
    }   // ColumnLayout

    UeActionResultIndicator
    {
        id: ueActionResultIndicator
    }   // UeActionResultIndicator
}   // Window
为什么选中标记显示后不会慢慢消失,也就是说,
PropertyAnimation
为什么没有开始?

您只显示图像

ueActionResultIndicator.state = "ueStateShown";
对于“消失”,您必须添加

ueActionResultIndicator.state = "ueStateHidden"
但是,无论如何,我认为,您必须重构此代码,并从没有状态的函数运行动画:

Rectangle {
    id: rect
    width: 100
    height: 62
    color: "green"
    PropertyAnimation
    {
        id: opacityAnimation
        properties: "opacity"
        target: rect
        from: 0.0
        to: 1.0
        duration: 1000

        loops: 3

        easing.type: Easing.InOutSine

        onStarted:
        {
            visible=true;
            enabled=true;
        }   // onStarted

        onStopped:
        {
            visible=false;
            enabled=false;
        }   // onStopped
    }   // PropertyAnimation

    function runAnimation() {
        opacityAnimation.running = true
    }
}

我现在明白我的错误了,但您能告诉我如何从函数运行它吗?更新答案。Welcome.hmm,现在我得到一个错误:
QML-PropertyAnimation:setRunning()不能在非根动画节点上使用。
。我正在更新答案中的示例。研究一下。如果在本例中调用func,它将正常工作。