设置工具按钮的背景颜色

Setting background colour for a tool button

我正在尝试为 Plasma 组件设置背景颜色,特别是 KDE 锁定屏幕中使用的键盘布局按钮。 (该按钮有时在浅色背景下很难看清,因此我试图将其调暗)。

这里是KeyboardLayoutButton.qml的完整内容我正在尝试修改:

import QtQuick 2.1
import QtQuick.Controls 1.1 as QQC

import org.kde.plasma.components 2.0 as PlasmaComponents

import org.kde.plasma.workspace.keyboardlayout 1.0

PlasmaComponents.ToolButton {
    id: kbLayoutButton

    iconName: "input-keyboard"
    implicitWidth: minimumWidth
    text: layout.currentLayoutDisplayName

    Accessible.name: i18ndc("plasma_lookandfeel_org.kde.lookandfeel", "Button to change keyboard layout", "Switch layout")

    visible: layout.layouts.length > 1

    onClicked: layout.nextLayout()

    KeyboardLayout {
          id: layout
              function nextLayout() {
              var layouts = layout.layouts;
              var index = (layouts.indexOf(layout.currentLayout)+1) % layouts.length;
              layout.currentLayout = layouts[index];
          }
    }
}

现在我可以在里面放置一个半透明的矩形 kbLayoutButton,它在那里是可见的,但它不会提高按钮文本的可见性,因为它是将文字广告放置在 上方只会降低对比度。我想在按钮 下方 下放置一个矩形。

据我了解,我需要将按钮设为彩色矩形的子项。

Rectangle {
   color: "black"
   PlasmaComponents.ToolButton {
     // full content of kbLayoutButton
   }
}

但是,当我尝试这样做时,按钮完全不可见。当我尝试将它包装在 Item.

中时也是如此

我是 QML 的新手,似乎找不到任何线索。如何设置背景?

我不熟悉等离子组件,但是你给 Rectangle 一个尺寸了吗?试试这个:

Rectangle {
    implicitWidth: toolButton.implicitWidth
    implicitHeight: toolButton.implicitHeight
    color: "black"

    PlasmaComponents.ToolButton {
        id: toolButton
        // full content of kbLayoutButton
    }
}