Hi
I implemented my own item model based on QAbstractTableModel.
The using QTreeView widget ONLY shows all my top level/root items, but no childs or expand indications.
I do NOT get any call on rowCount() with a valid parent. On call with invalid parent I return the number of top level items - works fine first depth.
I though that rowCount is called for each item to check if there are any childs.
DoubleClick... on the row didn't help, but the call should come anyway to show the "+" sign to indicate childs.

Something I missed or oversee... hope for some hints, THX

Here is most important of overritten functions (hope so):

Qt Code:
  1. QModelIndex HistoryQueryResultModel::index(int row, int column, const QModelIndex &parent) const {
  2. if (!hasIndex(row, column, parent)) {
  3. return QModelIndex();
  4. }
  5.  
  6. HistoryQueryResultModelEntry* item;
  7.  
  8. if (!parent.isValid()) {
  9. // unformtunately index() is const, and createIndex() uses non-const internal pointers to members, which become const because of index() is const
  10. // see https://development.qt-project.narkive.com/r2Uu03QQ/qabstractitemmodel-createindex-void-const
  11. item = const_cast<HistoryQueryResultModelEntry*>(m_entries[row]);
  12. } else {
  13. // unformtunately index() is const, and createIndex() uses non-const internal pointers to members, which become const because of index() is const
  14. item = const_cast<HistoryQueryResultModelEntry*>(static_cast<HistoryQueryResultModelEntry*>(parent.internalPointer())->child(row));
  15. }
  16. if (item) {
  17. return createIndex(row, column, item);
  18. } else {
  19. qt_assert("no item found", __FILE__, __LINE__);
  20. return QModelIndex();
  21. }
  22. }
  23.  
  24. QModelIndex HistoryQueryResultModel::parent(const QModelIndex &index) const {
  25. if (!index.isValid()) {
  26. qt_assert("invalid index", __FILE__, __LINE__);
  27. return QModelIndex();
  28. }
  29.  
  30. HistoryQueryResultModelEntry *childItem = static_cast<HistoryQueryResultModelEntry*>(index.internalPointer());
  31. HistoryQueryResultModelEntry *parentItem = childItem->parentItem();
  32.  
  33. if (!parentItem) {
  34. // we are on root element
  35. return QModelIndex();
  36. }
  37. return createIndex(parentItem->index(), 0, parentItem);
  38. }
  39.  
  40. int HistoryQueryResultModel::rowCount(const QModelIndex &parent) const
  41. {
  42. if (!parent.isValid()) {
  43. return m_entries.size();
  44. } else {
  45. qDebug("call for childs");
  46. HistoryQueryResultModelEntry *childItem = static_cast<HistoryQueryResultModelEntry*>(parent.internalPointer());
  47. if (!childItem) {
  48. qt_assert("invalid internal pointer for child", __FILE__, __LINE__);
  49. }
  50. return childItem->childCount();
  51. }
  52. }
  53.  
  54. int HistoryQueryResultModel::columnCount(const QModelIndex & parent) const
  55. {
  56. // invalid parent means m_entries[row].columns...
  57. return 4;
  58. }
To copy to clipboard, switch view to plain text mode