ComboBox QML 中的弹跳效果
Bounce effect in a ComboBox QML
我试图在拉动时更改组合框的背景颜色,直到出现“弹跳效果”。因为我在comboBox中的背景颜色是黑色的,但是在弹跳效果上背景的背景是白色的。
如果不可能,我至少希望能够停用这种效果“弹跳效果”。
我按照描述进行了尝试 here 但没有成功。
在此先感谢您的帮助。
您看到的白色背景来自嵌入在 ComboBox
中的 popup
属性,特别是 background.color
。要自定义它,the documentation recommends 您重新实现整个 popup
及其 ListView
contentItem
。重新实现这种类型可能会非常痛苦,因为您必须重新实现所有行为和视觉特征。当您只想调整一个 属性 或两个已经存在的
时,我发现这太过分了。
更简单的方法是在运行时设置属性。这是一个工作示例,展示了如何修改“反弹效果”颜色以及修改效果本身:
ComboBox {
id: comboBox
model: ["first", "second", "third"]
delegate: Rectangle { // My remake of your black-background delegates
color: "black"
implicitHeight: 20
implicitWidth: comboBox.width
Text {
anchors {
centerIn: parent
}
text: modelData
color: "lime"
}
}
// At runtime, reach into the comboBox.popup and set the background and boundsBehavior:
Component.onCompleted: {
comboBox.popup.background.color = "black" // Set "bounce" background color to black
comboBox.popup.contentItem.boundsBehavior = Flickable.StopAtBounds // Change/stop "bounce" behavior
}
}
我试图在拉动时更改组合框的背景颜色,直到出现“弹跳效果”。因为我在comboBox中的背景颜色是黑色的,但是在弹跳效果上背景的背景是白色的。
如果不可能,我至少希望能够停用这种效果“弹跳效果”。
我按照描述进行了尝试 here 但没有成功。
在此先感谢您的帮助。
您看到的白色背景来自嵌入在 ComboBox
中的 popup
属性,特别是 background.color
。要自定义它,the documentation recommends 您重新实现整个 popup
及其 ListView
contentItem
。重新实现这种类型可能会非常痛苦,因为您必须重新实现所有行为和视觉特征。当您只想调整一个 属性 或两个已经存在的
更简单的方法是在运行时设置属性。这是一个工作示例,展示了如何修改“反弹效果”颜色以及修改效果本身:
ComboBox {
id: comboBox
model: ["first", "second", "third"]
delegate: Rectangle { // My remake of your black-background delegates
color: "black"
implicitHeight: 20
implicitWidth: comboBox.width
Text {
anchors {
centerIn: parent
}
text: modelData
color: "lime"
}
}
// At runtime, reach into the comboBox.popup and set the background and boundsBehavior:
Component.onCompleted: {
comboBox.popup.background.color = "black" // Set "bounce" background color to black
comboBox.popup.contentItem.boundsBehavior = Flickable.StopAtBounds // Change/stop "bounce" behavior
}
}