Qml 在具有自定义ComboBoxStyle的ComboBox元素中居中放置标签
我正在使用Qml 在具有自定义ComboBoxStyle的ComboBox元素中居中放置标签,qml,qt5,qtquick2,Qml,Qt5,Qtquick2,我正在使用QtQuick.Controls 1.0和QtQuick.Controls.Styles 1.0,我找不到正确的方法来垂直和右侧对齐组合框的标签 这是我当前的代码 import QtQuick 2.0 import QtQuick.Controls 1.0 import QtQuick.Controls.Styles 1.0 ComboBox { id: comboCategories width: 230 height: 30 style: ComboBoxSt
QtQuick.Controls 1.0
和QtQuick.Controls.Styles 1.0
,我找不到正确的方法来垂直和右侧对齐组合框的标签
这是我当前的代码
import QtQuick 2.0
import QtQuick.Controls 1.0
import QtQuick.Controls.Styles 1.0
ComboBox {
id: comboCategories
width: 230
height: 30
style: ComboBoxStyle {
background: Rectangle {
id: rectCategory
width: comboCategories.width
height: comboCategories.height
color: "white"
}
label: Text {
anchors.verticalCenter: parent.verticalCenter
anchors.right: background.right
font.pointSize: 12
color: "#808080"
text: control.currentText
}
}
}
但是标签保持在我的元素的左上角,并且似乎不受锚的影响。我还试图用控件
或背景
替换父项
,但没有任何效果我不清楚这背后的原因,但如果我将文本
元素包装在项
中,那么我可以正确地
import QtQuick 2.0
import QtQuick.Controls 1.0
import QtQuick.Controls.Styles 1.0
ComboBox {
id: comboCategories
width: 230
height: 30
style: ComboBoxStyle {
background: Rectangle {
id: rectCategory
width: comboCategories.width
height: comboCategories.height
color: "white"
}
label: Item {
anchors.fill: parent
Text {
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: 5
font.pointSize: 12
color: "#808080"
text: control.currentText
}
}
}