Binding list from C++ to QML
-
But then now, I find out that the QAbstractTableModel may not the right choice :~) Despite I implemented columnCount(), it only ask for data in rows of column 0!!
That's right
GridVieworListViewonly deals with rows. In that case can't you replace it withQAbstractItemModel? Keep everything other than columns.@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? -
But then now, I find out that the QAbstractTableModel may not the right choice :~) Despite I implemented columnCount(), it only ask for data in rows of column 0!!
That's right
GridVieworListViewonly deals with rows. In that case can't you replace it withQAbstractItemModel? Keep everything other than columns.@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.
-
@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 useQAbstractItemModelwithGridView(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. -
@TonyN Congratulations :)
IMO you can useQAbstractItemModelwithGridView(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) ) -
@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) )