我正在尝试为等离子体组件设置背景颜色,特别是KDE锁定屏幕中使用的键盘布局按钮。(有时在轻度背景上可见该按钮,所以我试图将其变暗)。
这是键盘layoutbutton.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
}
}