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. Link a QTreeView to items in a QGraphicsScene
Forum Updated to NodeBB v4.3 + New Features

Link a QTreeView to items in a QGraphicsScene

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 653 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
    sasl
    wrote on last edited by
    #1

    This is not a code question, rather it's about how to use some Qt objects together. I hope it's appropriate here.

    I've got a QTreeView filled with items that inherit from QStandardItem and QGraphicsItem so that they can be added both to a QStandardItemModel and a QGraphicsScene.

    I'm now implementing signals for selection. I want the tree item to be selected when the graphics item is selected, and vice versa. It should also work for multiple selections, i.e. multiple clicked items in the scene should select multiple list items, and vice versa.

    I started to use selection signals to do this, but then I found out about QItemSelectionModel and I wondered if this was a better way to do this. It seems to allow list items to easily toggled/selected.

    I have no experience with QItemSelectionModel. I'm not quite sure how it is supposed to be used. For example, Is it supposed to be subclassed, and the class then used to handle the signal events? Or does it work some other way? If someone has an example of code that does something similar to what I'm trying to do (link items between a tree and a scene) then I'd be happy to see them!

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

      Hi
      I dont think you need to subclass it.
      Simply uses it with indexes to sync the selection of scene items with the
      Tree.

      https://doc.qt.io/qt-5/model-view-programming.html#handling-selections-in-item-views
      (see the code samples here for how to select something)

      If you combine the TreeView with
      https://doc.qt.io/qt-5/qpersistentmodelindex.html#details

      i think you can simply store the related index in the QGraphicsItem and use the/a

      QItemSelectionModel and its select function to handle having one or more selected items.

      That said , i have not tried this and there might be gotchas :)

      S 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        I dont think you need to subclass it.
        Simply uses it with indexes to sync the selection of scene items with the
        Tree.

        https://doc.qt.io/qt-5/model-view-programming.html#handling-selections-in-item-views
        (see the code samples here for how to select something)

        If you combine the TreeView with
        https://doc.qt.io/qt-5/qpersistentmodelindex.html#details

        i think you can simply store the related index in the QGraphicsItem and use the/a

        QItemSelectionModel and its select function to handle having one or more selected items.

        That said , i have not tried this and there might be gotchas :)

        S Offline
        S Offline
        sasl
        wrote on last edited by
        #3

        @mrjj Thanks! I have managed to get something working with the standard QItemSelectionModel. I guess it's just a case of keeping the scene items and list items synced with signals.

        1 Reply Last reply
        1

        • Login

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