Can we add multiple models and export it to qml? - qt

I have created a model and exported it to qml. Now qml list elements gets updated from this model but I need a nestedlist. On click of the outerlist element inner list gets opened and the innerlist is a separate model. Any examples ?

You can achieve that by using the TreeView control. There are a few examples in the Examples section of Qt Creator.

Related

Nested ListView in PyQt5 and QML

I need to create nested ListView. For example,
->Item1
-->Subitem1
-->Subitem2
->Item2
-->Subitem1
I have a dictionary data inside Python side. I need to display this data from QML ListView.
So, I should take the model from python and I should design collapsable ListView inside QML. I searched about this but I couldn't find example about it. I tried to create my own model but it didn't work.
Can someone help me?
Take a look at sections in ListView
https://doc-snapshots.qt.io/qt5-5.11/qml-qtquick-listview.html#section-prop

QML ListView delegate provider component

Currently im working on a complex program that parse large nested json into a tree and display it. I created a tree to parse data and a model to query data from tree to display it in QML ListView.
Now i need to create a some kind of delegate provider for this model. Each element in tree have its own delegate with different set of options and different qml items. And there must be an option to load new type of delegates in the runtime.
Is there are nice solution to do that? Some kind of custom C++ Loader component? I need an advise. I already know that it can be done using switch case and qml loader. But this solution is not acceptable for me.

Qt Quick Controls 2 and QAbstractTableModel

I have a model based on QAbstractTableModel that I would like to use to display its content in a list in QML.
Actually, I need to display the first column only.
TableView does not exist in Qt Quick Controls 2 and suffers from performance issue and rendering issues on HiDPI devices.
There is suggestion in this question to use a ListView. But I fail to see how I can tell the model that I need to display the first column only.
Is there any solution for this ?
This is automatically done in QML by ListView: the first column from the model is taken for any requested role.

QML Nested List View with separators

I'm trying to implement a tree view that represent structure of buildings/floors/rooms. All rooms should be classified by floor and building ( thus header for each building and floor is required.
First I implemented it with Repeater, Row and Grid elements. However i need a selection behaviour so i need to use ListView and GridView. However I have problems displaying nested list views.
Here's my code so far: http://pastie.org/private/3seqntgvskbyxnmnuluaua
Expected Result( when using Grid and Repeater instead of GridView and List View ):
Haven't tried it myself, but here is how to implementation a tree view in QML.
http://www.codeproject.com/Articles/632795/QML-TreeModel-and-TreeView
There is still no official tree view component in Qt (as of version 5.2). However, see the solution provided by jens on this thread
http://qt-project.org/forums/viewthread/30521
This is by far the best tree view that I have come across. It should provide a good basis for what you are trying to do.
Looks like Qt Company is releasing a QML TreeView in Qt5.5. Alpha release should be coming out in February.
http://blog.qt.io/blog/2015/02/05/licensing-of-new-modules-in-qt-5-5/

How to implement a tree view like the visual studio solution explorer with Qt?

I want to implement a tree view like the visual studio solution explorer with Qt. The tree is used to represent an external data called "project". I want to use Qt model/view architecture.
(1) QTreeView for the view, and the model is derived from QAbstractItemModel which include a pointer pointing to the project object.
(2) The items under a directory are sorted by its name. When adding an item under a directory, it will automatically be put on the right position.
(3) When double clicking an item in the tree, a dialog will pop up for editing.
Any good ways to implement the (2) and (3). Thanks a lot!
Ad 2) Taking a look here might be helpful: http://doc.qt.digia.com/qt/qsortfilterproxymodel.html. It contains examples of implementing a more complex sorting and filtering of the items.
Ad 3) Overrride QTreeView::mouseDoubleClickEvent().
Just a side note, as an alternative, you could use QTreeWidget and QTreeWidgetItem, in which case you might want to traverse the tree and insert child items directly at the position you want.

Resources