Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QML TreeView



  • Hi;

    What is the correct and easy way to display nested items with model in TreeView without C++ ?

    Thanks...



  • @VeNToR There is no built-in way in QML to do this. You have to have a QAbstractItemModel implementation. I recall seeing people discussing making a reusable model implementation that can be configured from data defined in QML but unless you can find something like this ready made somewhere, you will have to implement something in C++.



  • @Bob64 Thanks for your replay... I was think same as you, but I've tried to find a way... Thanks again...



  • @VeNToR This way is so long, It should not be hard as using QAbstractItemModel.

    for following model....

    ListModel
    {
    	id			:	chModel
    
    	ListElement
    	{		
    		text		:	"1"
    
    		elements	:	[
    							ListElement
    							{
    								text		:	"1.1"
    							}
    					]
    	}
    }


  • @VeNToR TreeView can be quite daunting when first encountered, especially if you are new to QML and Qt. It can be useful to start with an example that someone has already made and try to make changes that make it closer to your requirements. This should help you to understand how to implement a model. You might either end up gradually adapting it to what you need, or at some point you will be sufficiently confident to start from scratch based on the knowledge you have gained.

    If I remember correctly, this is one I referred to myself when I started out. I believe it's an adaptation to QML of one of Qt's own C++ QWidgets examples.



  • @Bob64 Thank you again... I'm not new on Qt and QML, but this is first time to use TreeView :) On the other hand, how can I extent my extension as ListElement feature like dynamic role ?
    like follows;

    MyElement
    {
    myRole : "test"
    .
    ..
    ...
    }

    "myRole" is dynamic (you can add many...), but my extension's must be defined by Q_PROPERTY.

    when I use any undefined role/property by Q_PROPERTY, I get this "Cannot assign to non-existent property" error.



  • @VeNToR I am really sorry but I don't think I understand well enough what you are trying to achieve to be able to make any sensible suggestions.


Log in to reply