Код: Выделить всё
ComboBox{
id: productSelection
anchors.fill: parent
//Layout.alignment: Qt.AlignCenter
font.bold: true
model: pinModel.getProductList()
property real radius: 8
//---------------------- label ----------------------
contentItem:Item {
Label {
anchors.centerIn: parent
//width: 200 //204
text: productSelection.displayText
font.family: FontStyle.contentFontBold.name
font.pointSize: FontStyle.h8
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
color: FontStyle.labelColor
}
}
//label
background: Rectangle{
id: labelBackground
color: productSelection.down ? Qt.darker(FontStyle.labelBackgroundColor,1.2) : FontStyle.labelBackgroundColor
radius: productSelection.radius
//border.width: productSelection.activeFocus ? 2 : 0.6
//border.color: borderColor //productSelection.activeFocus ? 'green' : 'yellow'//appStyle : borderColor
}
//---------------------------------------------------
//---------------------- Drop down section ----------------------
delegate: ItemDelegate {
id: itemDelegateHighlighter
width: labelBackground.width
height: 50 //productSelection.implicitHeight
hoverEnabled: true
focus: true
//drop down individual item background
background: Rectangle {
//anchors.fill: parent
anchors {left: parent.left; right: parent.right}
radius: productSelection.radius
color: itemDelegateHighlighter.hovered? FontStyle.backgroundColor: "transparent" //background color of hovered item
opacity: 0.6
}
//RowLayout {
RowLayout {
anchors.fill: parent
spacing: 10
Label {
text: modelData
font.family: FontStyle.contentFontBold.name
font.pointSize: FontStyle.h8 //font of drop down item
font.bold: true
color: FontStyle.textColor //itemDelegateHighlighter.hovered? 'white' : textColor
font.italic: itemDelegateHighlighter.hovered? true : false
Layout.leftMargin: 20
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
}
}
} //itemDelegate
onActivated: {
productIndex = currentIndex
product = currentText
pinModel.reloadDataFromJsonFile(product)
}
} //ComboBox
< /code>
Если я изменяю модель во время выполнения, как мне перезагрузить Combobox, чтобы он мог извлечь данные из последней модели? Мне нужен QML, чтобы отслеживать, если модель изменила и обновляла ComboBox в среде выполнения соответственно. < /P>
Я излучает сигнал из C ++ следующим образом: < /p>
void pinmodel :: clearitems ()
{< /p>
Q_EMIT beginResetModel();
//qDebug()
Подробнее здесь: [url]https://stackoverflow.com/questions/79772467/dynamically-updating-the-combobox-when-model-in-c-changes[/url]