[Interest] Updating a qml tableview model from a combo box delegate having a model
John Plummer
jcp at conecomp.com
Mon Sep 14 00:22:59 CEST 2015
No doubt this is a simple fix but I could not find any examples. I
have a Tableview defined in a qml
file. It is being 'sourced' several times from a view qml script and
passed a QObjectList model.
Everything displays fine and the TableViewColumns update the model
fine except for those with
a ComboBox delegate. Here's a code snippet showing the problem area:
TableView{
id:oetableview
....
TableViewColumn{
role:"pieces";
title:"Pieces";
width:50;
delegate:Item{
SpinBox{
id:currentPieces;
anchors.verticalCenter:parent.verticalCenter;
//decimals:2;
value:styleData.value;
width:parent.width
onEditingFinished:model.pieces=currentPieces.value.toString();
}
}
}
TableViewColumn{
role: "invoice_type" ;
title: "Inv Type" ;
width: 100 ;
delegate: Item {
ComboBox {
id: invoiceTypeCombo
width: 100
model: categoryModel
currentIndex: categoryModel.indexOf(styleData.value)
onActivated: {
model.invoice_type = invoiceTypeCombo.textAt(currentIndex)
console.log("Activated " + invoiceTypeCombo.textAt(currentIndex) + " " + styleData.value)
}
}
}
}
....
The model has identical set's for both roles:
void OEObject::setPieces(const QString &pieces)
{
if (pieces != m_pieces) {
m_pieces = pieces;
emit piecesChanged();
}
}
void OEObject::setInvoice_type(const QString &invoice_type)
{
if (invoice_type != m_invoice_type) {
m_invoice_type = invoice_type;
emit invoice_typeChanged();
}
}
The problem appears to be model.'role' = statement. The spinbox updates fine but the combobox does not. I'm
thinking the the combobox does work since the delegate has a model also. (The categoryModel is from C++ and is
used to populate the comboboxes only.) I've tried qualifying the model in the model.'role' statement but have
not found one that works. The log shows the correct value is there for assignment.
Does anyone have any suggestions? Thanks in advance.
Completely unrelated. I noticed that hovering over a spinbox allows the user to change its value without
giving it focus. This way of changing it does not fire the onEditingFinished unless the user clicks on the field.
Is this expected behavior?
jcp
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150913/67a05dcf/attachment.html>
More information about the Interest
mailing list