Unsolved QAbstractTableModel + QML TableView: How to call setData?
-
@VRonin Yes, I have just checked this. It overlaps my first row... Do you know either rows inserting and removing work? Meaning- If I remove or insert a row at runtime, will it update the view?
This seems to still be a very beta thing, I wonder either old or new controls should be used. -
@Bremenpl said in QAbstractTableModel + QML TableView: How to call setData?:
I also dont know how to force the QML TreeView to call the C++ headerData method
since you use QtQuick.Controls 1 TableView you need to use the TableViewColumn element, which only supports roles.
So you can add custom role names and forward those header roles to the headerData() method in the data() method.virtual QHash<int, QByteArray> roleNames() const { QHash<int, QByteArray> rn = QAbstractItemModel::roleNames(); rn[MyHeaderRole1] = QByteArrayLiteral("header1"); return rn; } QVariantdata(const QModelIndex &index, int role = Qt::DisplayRole) const { switch( role ) { case MyHeaderRole1: return headerData(0, Qt::Horizontal); ... } return QVariant(); }
-
@raven-worx thanks for answer. The thing is that at this point I am not certain anymore which version TableView I should opt for. On one hand I dont want to use the obsolete component which has columns and roles functionality mixed, and on the other this.new one doesnt seem to be ready for usage.
-
@Bremenpl said in QAbstractTableModel + QML TableView: How to call setData?:
and on the other this.new one doesnt seem to be ready for usage.
Based on the example from the docs (untested though):
TableView { id: tableView columnWidthProvider: function (column) { var colWidth = ...; var headerItem = headerRepeater.itemAt(column) if( headerItem ) headerItem.width = colWidth; return colWidth; } topMargin: header.height Row { id: header height: 40 width: implicitWidth padding: 0 spacing: 0 Repeater { id: headerRepeater model: tableView.columns Item { height: parent.height // your column delegate } } } }
Could be easier/built-in indeed, but i think this should work (with minor adaptions probably).
QAbstractItemModel::headerData() is directly invokable from within QML
-
@Bremenpl said in QAbstractTableModel + QML TableView: How to call setData?:
On one hand I dont want to use the obsolete component which has columns and roles functionality mixed, and on the other this.new one doesnt seem to be ready for usage.
I'm not aware of a possibility to use headers directly even in the old tebleview
-
@raven-worx Thanks for answer, but I am really lost at this one. What is supposed to be my column delegate?
I am playing with this new
TableView
for over an hour now and I am not even able to set variable columns width (when the container width change). I wonder either this is a bug or a feature. -
@VRonin But would you say the new one or old one is more fit to use...?
-
@Bremenpl said in QAbstractTableModel + QML TableView: How to call setData?:
What is supposed to be my column delegate?
what every you want it to look like. A Rectangle with a Text inside maybe?
-
@raven-worx I tried a simple
Text
component and all that was visible was a single text (not sure either they were stacked one on another).Arent you guys aware any single code example showing how to do this all from ground up?
-
I understand and share your frustration on the state of views in QML, development has been focused on components that work well on mobile platforms (as QtWidgets is not really an option there) so views have been neglected.
@Bremenpl said in QAbstractTableModel + QML TableView: How to call setData?:
Do you know either rows inserting and removing work?
It does, the example I linked actually does it
I have just checked this. It overlaps my first row
looks like you forgot the
topMargin: header.implicitHeight
part -
@Bremenpl said in QAbstractTableModel + QML TableView: How to call setData?:
I tried a simple Text component and all that was visible was a single text (not sure either they were stacked one on another).
maybe there is only 1 column?
is your model's columnCount() method called? -
@raven-worx It is. I will give it another go, thank you.
-
@VRonin Thanks for answer. I did snap a little bit, sorry for that...
I will give the newTableView
another go according to yours and @raven-worx hints but as for now I think the Version 1 is more complete. The only lacking thing is to make theTreeView
to callsetData
automatically (I only got this working in the new version). In the 1st version I am still calling a wrapper for it.Thank you for help guys.