TG-PlatformPlus/qml/debug/testfixture/common/QxComboBox.qml

53 lines
1.1 KiB
QML
Raw Normal View History

2026-03-02 14:29:58 +08:00
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
Item {
width: parent.width/parent.childcount
height: 58
property var currentIndex: -1
property var text: ""
property var cbmodel: ListModel{}
onCbmodelChanged: {
if (cbmodel.count > 0) {
selectItem(text)
}
}
clip: true
ComboBox {
id: cmb
currentIndex: find(parent.text)
width: 140
height: 32
anchors.centerIn: parent
textRole: "name"
font.pixelSize: 15
model: cbmodel
anchors.verticalCenter: parent.verticalCenter
onActivated: {
parent.text = model.get(currentIndex).name
parent.currentIndex = currentIndex
}
}
function selectItem(text)
{
cmb.currentIndex = findText(text)
currentIndex = cmb.currentIndex
}
function findText(text)
{
for(var i = 0; i < cbmodel.count; i++)
{
if(cbmodel.get(i).name == text)
{
return i;
}
}
return -1
}
}