Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTreeView & QStandardItemModel.
Qt 6.11 is out! See what's new in the release blog

QTreeView & QStandardItemModel.

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    seg_fault
    wrote on last edited by
    #1

    Hi Forum,

    I have a database that has tables representing Jobs and the Tasks associated with them.

    My goal is to display a QTreeView with a Job and then each task as a child below that; as well as a QTreeView with task categories and the tasks that fall into that category as children below that (in a different view).

    Currently, I am reading all the jobs and their tasks then constructing a QStandardItemModel and setting it to the QTreeView. This obviously only displays a copy of what is in the database and if any changes are made to the data elsewhere they aren't shown until the next manual update.
    I also want to display this model in a number of different views.

    What I have so far:
    @
    QStringList jobs = api->jobs();

    QStringList headerLabels;
    headerLabels << "Date" << "UUID" << "Assigned" << "Due Date" << "Status";
    m_stdmodel->setHorizontalHeaderLabels(headerLabels);
    
    foreach(const QString& job, jobs) {
        QList <QStandardItem *> jobItem;
        jobItem << new QStandardItem(api->jobTitle(job));
        QStringList tasks = api->tasksByJob(job);
        foreach(const QString& task, tasks) {
            QList<QStandardItem*> items;
            items << new QStandardItem(api->taskTitle(task));
            items << new QStandardItem(task);
            items << new QStandardItem(api->taskAssignee(task));
            items << new QStandardItem(api->taskDue(task));
            items << new QStandardItem(api->taskStatus(task));
            //
            jobItem.at(0)->appendRow(items); // append child items to top-level item
        }
        m_stdmodel->appendRow(jobItem);
    }
    table.setModel(m_stdmodel);
    

    @

    What should I be doing so that I am working directing with the data and not a copy of it?
    So far I haven't been able to get a model into a QTreeView other than by manufacturing a QStandardItemModel.

    Edit: Should I be using an QAbstractProxyModel?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved