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

Using C++ QAbstractTableView in Qml



  • I have a QtWidgets app that uses a QTableView with a custom C++ QAbstractTableModel. I need to implement this on iPad so I am going with QtQuick. It looks like both the TableViews in QtQuick.Controls is not a drop-in replacement for QTableView. In fact, the semantics of "roles" appears to be totally different, where it asks for a particular role instead of a particular column.

    What's the rationale behind that strange semantic change? And what is the best way to replicate the functionality of a QTableView with a C++ QAbstractTableModel?

    Thanks!



  • I think the QtQuick Tableview would be a drop-in replacement, although you need to do the styling and headers on your own.

    And yes the QuickControls1 TableView will not take columns into account, but uses roles instead.

    My suggestion, use the QtQuick TableView and do your custom delegates and headers (and selection, sorting...)



  • @maxwell31 said in Using C++ QAbstractTableView in Qml:

    I think the QtQuick Tableview would be a drop-in replacement, although you need to do the styling and headers on your own.

    And yes the QuickControls1 TableView will not take columns into account, but uses roles instead.

    My suggestion, use the QtQuick TableView and do your custom delegates and headers (and selection, sorting...)

    Yep, it looks like QtQtuick.Controls.TableView is the way to go there. Thanks!



  • But it is true that Qt should provide a QML Item which already provides support for headers, selection, sorting...


Log in to reply