Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qt5.6: TreeView not updating?
Forum Updated to NodeBB v4.3 + New Features

Qt5.6: TreeView not updating?

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 527 Views
  • 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.
  • H Offline
    H Offline
    HennsWoerst
    wrote on last edited by
    #1

    Hello!

    I am aware that Qt5.6 is currently in alpha, but I need the "setRootIndex()" method for my project. My problem is that the view is not updating (only if I close the treebranch and reopen it, I can see the changed value). I am pretty sure that I implemented the model correctly and was wondering, if this is a known issue?

    Here's some code:

    The View:

    @
    TreeView {
    id: treeView

    anchors.fill: parent
    anchors.margins: 1
    headerVisible: false
    backgroundVisible: false
    alternatingRowColors: false
    frameVisible: false
    
    model: treeModel
    
    selection: ItemSelectionModel {
        model: treeModel
    }
    
    TableViewColumn {
        role: "baseName"
    }
    

    }
    @

    I hand the new data over to C++ and do:

    @
    m_model->setData(m_index, m_newName, TreeModel::BaseNameRole);
    @

    In the model:

    @
    bool TreeModel::setData(const QModelIndex &index, const QVariant &value, int role)
    {
    if (!index.isValid())
    return false;

    TreeItem* item = getItem(index);
    
    switch (role)
    {
    case BaseNameRole:
    	item->setBaseName(value.toString());
    	break;
    
    case ValueRole:
    	item->setValue(value);
    	break;
    
    case MetaDataRole:
    	item->setMetaData(value.toMap());
    	break;
    }
    
    emit dataChanged(index, index);
    
    return true;
    

    }
    @

    Still, the changes do not show up until I open and close the treebranch. Is this a bug in the TreeView?

    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