53 lines
1.1 KiB
QML
53 lines
1.1 KiB
QML
|
|
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
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|