ComboBoxStyle QML QT 标签不工作
ComboBoxStyle QML QT Label not working
我正在尝试自定义组合框上的标签,但它似乎不起作用,我有以下代码:
ComboBox {
id:tableName
editable: true
currentIndex: 0
model: eventModel.getTables()
anchors.left: parent.left; anchors.leftMargin: 20
y: parent.height/10
width: buttonWidth
height: 70
style: ComboBoxStyle {
id:comboStyle
background: Rectangle {
id: rectCategory
width: control.width
height: control.height
color: "#FFECECEC"
Text {
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: 2
font.pointSize: 15
font.family: "sans serif"
color: control.hovered?"#FF6BC1E5":"#FF404040"
text:"˅"
}
}
label: Label{
Rectangle{anchors.fill: tableName; color:"red"}
anchors.right: parent.right
anchors.rightMargin:10
font.pointSize: 12
font.family: "sans serif"
color: "black"
text:control.currentText
}
// drop-down customization here
property Component __dropDownStyle: MenuStyle {
__maxPopupHeight: 600
__menuItemType: "comboboxitem"
frame: Rectangle { // background
color: "#FFACACAC"
}
itemDelegate.label: Text {
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.pointSize: 12
font.family: "sans serif"
color: styleData.selected ? "#FF6BC1E5" : "#FF404040"
text: styleData.text
}
itemDelegate.background: Rectangle { // selection of an item
color: styleData.selected ? "#FF404040" : "#FFECECEC"
}
__scrollerStyle: ScrollViewStyle { }
}
}
下拉自定义似乎工作得很好,但标签保持不变,这是我得到的输出:
感谢 jpnurmi,我找到了一种行之有效的风格:
ComboBoxStyle {
id:comboStyle
textColor:"blue"
font{
pointSize:15
family:"sans serif"
}
background: Rectangle {
id: rectCategory
width: control.width
height: control.height
color: "#FFECECEC"
Image {
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: 5
source:control.hovered?"images/select2.png":
"images/select.png"
}
}
__editor:
Rectangle {
anchors.fill: parent
color: "#00000000"
}
// drop-down customization here
property Component __dropDownStyle: MenuStyle {
__maxPopupHeight: 600
__menuItemType: "comboboxitem"
frame: Rectangle { // background
color: "#FFACACAC"
}
itemDelegate.label: Text {
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.pointSize: 12
font.family: "sans serif"
color: styleData.selected ? "#FF6BC1E5" : "#FF404040"
text: styleData.text
}
itemDelegate.background: Rectangle { // selection of an item
color: styleData.selected ? "#FF404040" : "#FFECECEC"
}
__scrollerStyle: ScrollViewStyle { }
}
}
只读标签用于不可编辑的 ComboBox
。试试这个:
style: ComboBoxStyle {
font.pointSize: 12
font.family: "sans serif"
textColor: "black"
background: Rectangle {
...
}
__editor: Rectangle {
color: "red"
}
...
}
我正在尝试自定义组合框上的标签,但它似乎不起作用,我有以下代码:
ComboBox {
id:tableName
editable: true
currentIndex: 0
model: eventModel.getTables()
anchors.left: parent.left; anchors.leftMargin: 20
y: parent.height/10
width: buttonWidth
height: 70
style: ComboBoxStyle {
id:comboStyle
background: Rectangle {
id: rectCategory
width: control.width
height: control.height
color: "#FFECECEC"
Text {
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: 2
font.pointSize: 15
font.family: "sans serif"
color: control.hovered?"#FF6BC1E5":"#FF404040"
text:"˅"
}
}
label: Label{
Rectangle{anchors.fill: tableName; color:"red"}
anchors.right: parent.right
anchors.rightMargin:10
font.pointSize: 12
font.family: "sans serif"
color: "black"
text:control.currentText
}
// drop-down customization here
property Component __dropDownStyle: MenuStyle {
__maxPopupHeight: 600
__menuItemType: "comboboxitem"
frame: Rectangle { // background
color: "#FFACACAC"
}
itemDelegate.label: Text {
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.pointSize: 12
font.family: "sans serif"
color: styleData.selected ? "#FF6BC1E5" : "#FF404040"
text: styleData.text
}
itemDelegate.background: Rectangle { // selection of an item
color: styleData.selected ? "#FF404040" : "#FFECECEC"
}
__scrollerStyle: ScrollViewStyle { }
}
}
下拉自定义似乎工作得很好,但标签保持不变,这是我得到的输出:
感谢 jpnurmi,我找到了一种行之有效的风格:
ComboBoxStyle {
id:comboStyle
textColor:"blue"
font{
pointSize:15
family:"sans serif"
}
background: Rectangle {
id: rectCategory
width: control.width
height: control.height
color: "#FFECECEC"
Image {
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: 5
source:control.hovered?"images/select2.png":
"images/select.png"
}
}
__editor:
Rectangle {
anchors.fill: parent
color: "#00000000"
}
// drop-down customization here
property Component __dropDownStyle: MenuStyle {
__maxPopupHeight: 600
__menuItemType: "comboboxitem"
frame: Rectangle { // background
color: "#FFACACAC"
}
itemDelegate.label: Text {
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.pointSize: 12
font.family: "sans serif"
color: styleData.selected ? "#FF6BC1E5" : "#FF404040"
text: styleData.text
}
itemDelegate.background: Rectangle { // selection of an item
color: styleData.selected ? "#FF404040" : "#FFECECEC"
}
__scrollerStyle: ScrollViewStyle { }
}
}
只读标签用于不可编辑的 ComboBox
。试试这个:
style: ComboBoxStyle {
font.pointSize: 12
font.family: "sans serif"
textColor: "black"
background: Rectangle {
...
}
__editor: Rectangle {
color: "red"
}
...
}