Qml 项目无法编译,错误'Expected token `,'



Qt Creator 3.1.2基于Qt 5.3.1 (MSVC 2010, 32位)。项目导入了QmlProject 2.0这是我的程序,我有这个错误。这个程序来自教程,它对他有效,所以我不确定那里有什么问题。

import QtQuick 2.0
Rectangle {
    id: rootTangle
    width: 360
    height: 360
    color: "red"
    hoverEnabled: true;

    Rectangle {
        id: blueRec
        color:  "blue"
        //opacity:    .50
        width: rootTangle.width/2
        height: rootTangle.width/6
        anchors.centerIn: rootTangle
        border.color: "black"
        border.width: 7
        rotation: 180
        radius: 20
        gradient: Gradient {
                GradientStop { position: 0.0; color: "#b0c5de" }
                GradientStop { position: 1.0; color: "blue" }
        }
    }
    Text {
        id: nazdarTxt
        anchors.centerIn: blueRec
        text: "Nazdar"
        clip: false
        visible: true
        font.family: "Times New Roman"
        font.bold: true
        //font.pixelSize: Math.round(blueRec.height/3)
        width: blueRec.width
        //wrapMode: Text.WordWrap
    }
    MouseArea {
        id: blueRecMouseArea
        hoverEnabled: true;
        onEntered: {
            blueRec.color: "brown"
        }
        anchors.rightMargin: 0
        anchors.bottomMargin: 0
        anchors.leftMargin: 1
        anchors.topMargin: 0
        anchors.fill: blueRec
        onClicked: {
            Qt.quit();
        }
    }
}
错误在第46行:onEntered: { blueRec.color: "brown" }

问题是后面的冒号color:

onEntered: {
    blueRec.color: "brown"
}

应该改成等号:

onEntered: {
    blueRec.color = "brown"
}

也没有hoverEnabled矩形,所以你需要删除或注释它:

Rectangle {
    id: rootTangle
    width: 360
    height: 360
    color: "red"
    //hoverEnabled: true;
由于您已经为blueRec定义了渐变,更改其颜色没有效果,您应该改为更改渐变颜色:
onEntered: {
  blueRec.gradient.stops[0].color = "brown"
  blueRec.gradient.stops[1].color = "white"
}

相关内容

  • 没有找到相关文章

最新更新