Results 1 to 9 of 9

Thread: QmlTreeView 5.6 itemDelegate

  1. #1
    Join Date
    Jan 2010
    Posts
    95
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QmlTreeView 5.6 itemDelegate

    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
    Qt Code:
    1. TableViewColumn {
    2. title: "Name"
    3. role: "name"
    4. resizable: true
    5. }
    To copy to clipboard, switch view to plain text mode 

    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.

    Qt Code:
    1. Text {
    2. id: label
    3. text: model.name
    4. font.family: "Open Sans"
    5. font.pixelSize: 13
    6. font.weight: Font.DemiBold
    7. elide: "ElideRight"
    8. anchors.verticalCenter: parent.verticalCenter
    9. width: parent.width - iconImage.width - 25
    10. }
    11. Image {
    12. id: iconImage
    13. height: 24
    14. anchors.right: parent.right
    15. anchors.rightMargin: 25
    16. fillMode: Image.PreserveAspectFit
    17. anchors.verticalCenter: parent.verticalCenter
    18. source: model.visible?"qrc:/icons/Visible.png": "qrc:/icons/Invisible.png"
    19. MouseArea {
    20. anchors.fill: parent
    21. hoverEnabled: true
    22. onClicked: {
    23. qmlApp.onTreeItemVisibleChanged(treeView.model.modelIndex(model.index), !model.visible)
    24. }
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QmlTreeView 5.6 itemDelegate

    Does the model correctly emit the dataChanged() signal?

    Does it work in a test application using QTreeView?

    Cheers,
    _

  3. #3
    Join Date
    Jan 2010
    Posts
    95
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QmlTreeView 5.6 itemDelegate

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QmlTreeView 5.6 itemDelegate

    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,
    _

  5. #5
    Join Date
    Jan 2010
    Posts
    95
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QmlTreeView 5.6 itemDelegate

    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

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QmlTreeView 5.6 itemDelegate

    Quote Originally Posted by volcano View Post
    The model is created the same way as the QTreeView example
    So the model works as expected when shown in a QTreeView?

    Quote Originally Posted by volcano View Post
    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,
    _

  7. #7
    Join Date
    Jan 2010
    Posts
    95
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QmlTreeView 5.6 itemDelegate

    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?

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QmlTreeView 5.6 itemDelegate

    You already have that.

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

    Cheers,
    _

  9. #9
    Join Date
    Jan 2010
    Posts
    95
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QmlTreeView 5.6 itemDelegate

    Could you help me with an working example where the backend model updates the Qml TreeView?

Similar Threads

  1. Best approach to set a itemdelegate strategy?
    By tonnot in forum Qt Programming
    Replies: 0
    Last Post: 31st October 2011, 16:49
  2. QtextDocument-ItemDelegate and Painting
    By LynneV in forum Qt Programming
    Replies: 2
    Last Post: 15th November 2010, 16:10
  3. Replies: 2
    Last Post: 14th November 2010, 08:54
  4. Display ItemDelegate Editor always
    By gast23 in forum Qt Programming
    Replies: 6
    Last Post: 6th September 2010, 04:33
  5. Color table row with ItemDelegate
    By dexjam in forum Newbie
    Replies: 8
    Last Post: 29th June 2006, 12:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.