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

Model - view problem



  • I create a file browser with additional functions and data.
    I implemented an own hierarchical model derived from QAbstractItemModel for my data structure.
    I want to display hierarchical data (files and directories) two ways;

    1. with a tree view, like this:

    plants
    ---rose
    ---fruits
    ------grape
    ------apple
    ------pear
    animals
    ---dog

    1. with a table view (nodes have columns), like this (only files):

    plants/rose
    plants/fruits/grape
    plants/fruits/apple
    plants/fruits/pear
    animals/dog

    My problem is QTableView can display data directly under a specified node (QModelIndex), on one level.
    I can set the root node (QModelIndex) with setRootIndex(), but I want to
    display all hierarchical data (except directories), as shown.

    Creating a model is useful, because I want to edit data, too, using the different widgets.

    What is the correct way to solve this problem? Creating an own view derived from QTableView?

    Thanks.


Log in to reply