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. How to reset a full treeView ?
Forum Updated to NodeBB v4.3 + New Features

How to reset a full treeView ?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 2.1k 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.
  • the moebiusT Offline
    the moebiusT Offline
    the moebius
    wrote on last edited by
    #1

    Hello everyone
    First of all, I have to say I'm a total newby with QtQuick and prefer Widgets. However, I had to take a step in and to learn asap...and google can't answer all my issues, unfortunatly.

    I'm setting a copy option for some elements in my tree, edit those element on another page, then on complete resent the whole model and come back on the tree.
    My issue is : the tree isn't updated between the two pages
    I tried
    emit dataChanged(QModelIndex(), QModelIndex());
    but it doesn't seems to affect the tree.
    moreover, the tree doesn't respond anymore to right click or expand, so I guess it has more or less been affected...but can't realy understand how.

    model function :

    void TreeModel::rebuild()
    {
        cleanTree(rootItem);
        fillModelBuilding(m_buidlings.existingBuildingList());
        emit dataChanged(QModelIndex(), QModelIndex());
    }
    

    view :

    Item{
        TreeView {
            width: parent.width
            height: parent.height
            id:buildingTreeId
            anchors.fill: parent
            model: siteTree
    
    MouseArea
            {
                anchors.fill: parent
                acceptedButtons: Qt.RightButton
                onReleased:
                {
                   if (mouse.button === Qt.RightButton)
                    {
                         contextMenuArea.popup()
                     }
                }
            }
    Menu
            {
                id: contextMenuArea
    MenuItem
                {
                    text: qsTr('Copier l\'emplacement')
                    onTriggered:{
                        stackView.pushItem({item: Qt.resolvedUrl("AreaCopyForm.qml")})
                    }
                }
    selection: ItemSelectionModel
            {
                id:sel
                model: siteTree
            }
            selectionMode: SelectionMode.SingleSelection
    
    TableViewColumn
            {
                role: "name_role"
                title: "Site"
            }
    }
    

    I cleaned up the view to avoid too much "polution"...but I think all the important stuff is here

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      Hi and welcome to devnet,

      The first strange thing is that you pass two invalid model indexes, so there's not reason for the views to update anything since both the top left and bottom right indexes points to nowhere in the model.

      From the code of your function it rather looks like you are reseting your whole model. beginResetModel and endResetModel might be a better choice.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      the moebiusT 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi and welcome to devnet,

        The first strange thing is that you pass two invalid model indexes, so there's not reason for the views to update anything since both the top left and bottom right indexes points to nowhere in the model.

        From the code of your function it rather looks like you are reseting your whole model. beginResetModel and endResetModel might be a better choice.

        Hope it helps

        the moebiusT Offline
        the moebiusT Offline
        the moebius
        wrote on last edited by
        #3

        @SGaist and it worked perfectly
        Thank you a lot...I should bake you a cookie statue for this
        I had found the two index idea here : [http://stackoverflow.com/questions/29141038/what-does-bottomright-mean-when-using-datachanged-with-a-qtreeview-in-qt]
        but it clearly wasn't adapted for the situation.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You're welcome !

          A cookie statue ? Sounds delicious :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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