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. QUndoStack across 2 cpps? QTreeView and QGraphicsScene
Forum Updated to NodeBB v4.3 + New Features

QUndoStack across 2 cpps? QTreeView and QGraphicsScene

Scheduled Pinned Locked Moved Solved General and Desktop
qundostackqundocommandc++qtqtreeviewqgraphicsscene
26 Posts 3 Posters 6.5k 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.
  • JonBJ JonB

    @StudentScripter
    It seems to me you have two possible general approaches:

    • Use signals & slots to communicate between the tree view and the graphics scene. This can alleviate the need for each side to know too much about the other side. But be careful not to get into an "infinite loop", where each side "ping pongs" signals between themselves for some change.

    • As @SGaist says, create a common model and share the model between both sides. For example, QStandardItem is part of a QStandardItemModel. You can already have multiple views (e.g. QTreeView) attached to the same model, make it so (some wrapper around) the QGraphicsScene shares that model with your one QTreeView. All your operations, like selecting or clicking a checkbox, should be implemented in the model, not the view or scene. Then that emits signals like dataChanged() or selectionChanged() in response to your actions and both views get notified about it and react in their own ways. The model code can be kept in its own/class/module/file, that is included into both the tree view & graphics scene classes, they should not need to see each other directly. This would be my inclination.

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #21

    @JonB said in QUndoStack across 2 cpps? QTreeView and QGraphicsScene:

    The model code can be kept in its own/class/module/file, that is included into both the tree view & graphics scene classes, they should not need to see each other directly. This would be my inclination.

    S 1 Reply Last reply
    1
    • JonBJ JonB

      @JonB said in QUndoStack across 2 cpps? QTreeView and QGraphicsScene:

      The model code can be kept in its own/class/module/file, that is included into both the tree view & graphics scene classes, they should not need to see each other directly. This would be my inclination.

      S Offline
      S Offline
      StudentScripter
      wrote on last edited by
      #22

      @JonB Ok and from their i add an setter in the qtreeview class and the viewlayerlist to retrieve the model.

      JonBJ SGaistS 2 Replies Last reply
      0
      • S StudentScripter

        @JonB Ok and from their i add an setter in the qtreeview class and the viewlayerlist to retrieve the model.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #23

        @StudentScripter Yes, a suitable public getter & setter for the model called from each of the QTreeView and QGraphicsScene modules.

        1 Reply Last reply
        0
        • S StudentScripter

          @JonB Ok and from their i add an setter in the qtreeview class and the viewlayerlist to retrieve the model.

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #24

          @StudentScripter QTreeView already has a setter for the model. You just need to add one to your QGraphicsScene subclass.

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

          S 1 Reply Last reply
          0
          • SGaistS SGaist

            @StudentScripter QTreeView already has a setter for the model. You just need to add one to your QGraphicsScene subclass.

            S Offline
            S Offline
            StudentScripter
            wrote on last edited by
            #25

            @SGaist Yep done everything and works fine. :D

            SGaistS 1 Reply Last reply
            0
            • S StudentScripter

              @SGaist Yep done everything and works fine. :D

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #26

              @StudentScripter great !

              Then please mark the model as solved using the "Topic Tools" button or the dotted menu beside the answer you deem correct so that other forum users may know a solution has been found :-)

              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
              • S StudentScripter has marked this topic as solved on

              • Login

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