Binding list from C++ to QML
-
@p3c0 Uh but then which view should I use? I read this,
"QAbstractItemModel presents a hierarchy of tables, but the views currently provided by QML can only display list data."
Does that mean, at the present time, nothing I can use except maybe create my own view!? If so, what is the best reading can you recommend? -
@p3c0 I solved the problem! Even without doing custom roles. I just simplified it, adding some qRegisterMetaType. The solution is not as I want to be, but it works. For now, I just have to figure out how to hide the dummy items. Thank you for pointing out some direction.
-
@TonyN Congratulations :)
IMO you can useQAbstractItemModel
withGridView
(for grid like item positioning) orListView
(for list like item positioning). For hiding dummy items you can maintain a field for items and update it from the model whenever required. -
@p3c0 I certainly want to hear other opinion. I did attempt to use QAbstractItemModel, but then the GridView still treat model as a list!?
(my current solution is using QAbstractListModel with GridView, and compute item's index from its specified row and column, if there is no item at the requested index, I just return QVariant(). The rowCount() of QAbstractItemModel is the total item the can represent on the grid (row * column) )