PDA

View Full Version : QmlTreeView 5.6 itemDelegate



volcano
31st March 2016, 11:03
Hi all,

I'm using QML treeview 5.6, I have a QAbstractItemModel subclass model which is set to the model of the treeview.
The model has roles such as visible and name.

The tree view has a tableview column


TableViewColumn {
title: "Name"
role: "name"
resizable: true
}


And in the item delegate, I'm accessing the name as "model.name" and visible as "visible"
Delegate has a name and an icon field.



Text {
id: label
text: model.name
font.family: "Open Sans"
font.pixelSize: 13
font.weight: Font.DemiBold
elide: "ElideRight"
anchors.verticalCenter: parent.verticalCenter
width: parent.width - iconImage.width - 25
}
Image {
id: iconImage
height: 24
anchors.right: parent.right
anchors.rightMargin: 25
fillMode: Image.PreserveAspectFit
anchors.verticalCenter: parent.verticalCenter
source: model.visible?"qrc:/icons/Visible.png": "qrc:/icons/Invisible.png"
MouseArea {
anchors.fill: parent
hoverEnabled: true
onClicked: {
qmlApp.onTreeItemVisibleChanged(treeView.model.mod elIndex(model.index), !model.visible)
}
}
}


The reset of the property is happening in the C++ model, however it's not reflected in the QML file.

Kindly advice what i'm missing

anda_skoa
31st March 2016, 11:27
Does the model correctly emit the dataChanged() signal?

Does it work in a test application using QTreeView?

Cheers,
_

volcano
31st March 2016, 12:15
I haven't tried the test application in QTreeView. Could you detail me the location for the same?

dataChanged() is emitted, however it's not connected to any slot.

anda_skoa
31st March 2016, 13:57
The connection is somewhere internal in the view code, you only need to make sure it is emitted correctly, i.e. for the correct model index(es).

Not sure what you mean with "location for the same", QTreeView is linked in the previous comment, it is in QtWidgets.

Cheers,
_

volcano
1st April 2016, 04:54
Hi,

The model is created the same way as the QTreeView example, however in the Qt documentation for QML treeview it's mentioned "Note: For performance reasons, created delegates can be recycled across multiple table rows. This implies that when you make use of implicit properties such as styleData.row or model, these values can change after the delegate has been constructed. This means that you should not assume that content is fixed when Component.onCompleted is called, but instead rely on bindings to such properties."

The implementation of each child item is a list of qvariant element.

How do i create bindings in this scenario?

Kindly advice

anda_skoa
1st April 2016, 08:51
The model is created the same way as the QTreeView example

So the model works as expected when shown in a QTreeView?



however in the Qt documentation for QML treeview it's mentioned "Note: For performance reasons, created delegates can be recycled across multiple table rows. This implies that when you make use of implicit properties such as styleData.row or model, these values can change after the delegate has been constructed. This means that you should not assume that content is fixed when Component.onCompleted is called, but instead rely on bindings to such properties."

How is that relevant here, you are not using Component.onCompleted.

Cheers,
_

volcano
1st April 2016, 09:35
Yes the model works in the QTreeView.

Regarding the second point "but instead rely on bindings to such properties.", how can I achieve this bindings in Qml TreeView?

anda_skoa
1st April 2016, 10:13
You already have that.

E.g. the "label"'s text property is bound to model.name

Cheers,
_

volcano
3rd April 2016, 05:47
Could you help me with an working example where the backend model updates the Qml TreeView?