如何将弹出式背景色设置为透明

时间:2019-11-30 21:54:46

标签: qt qml qtquickcontrols2

游戏结束时,我将显示以下弹出窗口:

Popup {
    id: popup
    anchors.centerIn: parent
    Text{
        text: "Game Over!!" + "\n\n" + "New High Score: "+ score_val
        anchors.centerIn: canvas
        color: "grey"
        font.pixelSize: 70
        font.family: gill.name
    }
    modal: true
    focus: true
    closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent

}

一切都很好,但是背景是白色,似乎没有背景颜色属性,我该怎么办?

1 个答案:

答案 0 :(得分:1)

您必须将一项设置为background属性:

Popup {
    id: popup
    anchors.centerIn: parent
    Text{
        text: "Game Over!!" + "\n\n" + "New High Score: "+ score_val
        anchors.centerIn: canvas
        color: "grey"
        font.pixelSize: 70
        font.family: gill.name
    }
    background: Rectangle {
        color: "transparent"
        border.color: "black"
    }
    modal: true
    focus: true
    closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
}