QML ToolButton 背景颜色

QML ToolButton background colour

我有以下 QML:

    ToolButton {
        id: frameCapButton
        height: mainWindow.iconHeight
        width: height

        background: Rectangle {
            radius: 2
            border.width: (imageCaptureModel.imageType == ImageCaptureModel.ImageTypeFrame) ? 2 : 0
            border.color: (imageCaptureModel.imageType == ImageCaptureModel.ImageTypeFrame) ? "#ff0000" : "transparent"
        }
        contentItem: ColoredImage {
            source: "ImageViewer/framecapture.svg"                            
            color: Colours.buhlerGreen()
        }
        onClicked: {
            imageCaptureModel.imageType = ImageCaptureModel.ImageTypeFrame
            placeHolder = frameText
            pixelField.text = ""
        }
    }

我添加了块 "background" 并且它给整个按钮一个白色背景,为什么?如何保留边框并松开白色背景?

QML 中的 color 属性 可以使用 QColor 或字符串(当然也可以绑定到另一个 属性)参见 Qt Docs

在这种情况下,您正在为其提供名为 transparent 的 属性,但 QML 无法找到它:

qrc:/main.qml:23: ReferenceError: transparent is not defined

当您尝试以下操作时,您将获得透明背景:

color: "transparent"