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. QAbstractItemModel & QTreeView notifications...
Forum Updated to NodeBB v4.3 + New Features

QAbstractItemModel & QTreeView notifications...

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.2k Views 2 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.
  • D Offline
    D Offline
    Dariusz
    wrote on last edited by aha_1980
    #1

    Hey

    I'm trying to wrap my head around item model system.

    Say I have
    treeViewA
    treeViewB
    boths use
    modelA

    to display data. Say in treeViewA I 2x click on an item and rename it, the name changes in treeViewA but also in treeViewB. Which means that setData, was sent to model, which forwarded it to item, and then the models must have notified the treeViews that data has changed and they need to redraw. I take there are either full redraw flags or just changed item flags. What I want to know is, what function does model call on treeView that tells it to redraw, how can I subclass it/replace it? Say my treeViews is linked to a widget displaying data of the selected item, if selection change, then every treeView should notify their own data widgets to update as well. Another example could be that if I rename a item, I would want that rename to trigger other events too for each treeViews.

    Can any1 hint me in to right direction?

    TIA

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

      Hi,

      dataChanged is the signal you are looking for.

      The setData and data methods will also interest you.

      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
      3
      • D Offline
        D Offline
        Dariusz
        wrote on last edited by Dariusz
        #3

        Sweet thanks! I had a feeling that was it but I was not 100% sure.

        Wait thats dataChanged on model one, what about treeView one? I need tree to react to data/specific data change not model.

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

          @Dariusz said in QAbastractItemModel & QTreeView notifications...:

          Wait thats dataChanged on model one, what about treeView one? I need tree to react to data/specific data change not model.

          What you are asking here is not really clear.

          Your views are going to get notified that something has changed and are going to re-read the model's data to update the concerned items.

          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
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by Chris Kawa
            #5

            What I want to know is, what function does model call on treeView that tells it to redraw

            None. Model doesn't know anything about the existance of a view (or views). The relationship is the inverse - it's the view that connects to model's signals when you call setModel() on it. As for what signals are emmited by the model - see the documentation of QAbstractItemModel. There are pairs of before/after signals for different operations, e.g. rowsAboutToBoInserted()/rowsInserted(). There's also the mentioned dataChanged() for when a range of items changes one of its roles values.

            Say my treeViews is linked to a widget displaying data of the selected item, if selection change, then every treeView should notify their own data widgets to update as well.

            Selection is not a function of the model. This is handled by a selection model that is set on the view, so each view has its own. You can connect to its selectionChanged() signal.

            Another example could be that if I rename a item, I would want that rename to trigger other events too for each treeViews.

            This you can handle by connecting to the dataChanged() signal of the model as mentioned above

            Wait thats dataChanged on model one, what about treeView one? I need tree to react to data/specific data change not model.

            The data changes in the model so you connect to the model's signals not the view. The views provided by Qt already connect to all the signals of the model. If you want to do extra things in the view you can subclass and connect again to the signals of your choice. You can make the connections in the override of setModel() of your subclass.

            1 Reply Last reply
            4

            • Login

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