Results 1 to 9 of 9

Thread: How to communicate btw QGraphicsScene and QTreeWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How to communicate btw QGraphicsScene and QTreeWidget

    Either have a global hash (or event two) to map between objects or have pointers to appropriate graphicsitems in tree items and vice-versa.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #2
    Join Date
    Dec 2008
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default Re: How to communicate btw QGraphicsScene and QTreeWidget

    Quote Originally Posted by wysota View Post
    Either have a global hash (or event two) to map between objects or have pointers to appropriate graphicsitems in tree items and vice-versa.
    ah yeah, youre right... a hash table should work.

    But the other method (storing the pointers inside the items) sounds even better.
    Lets say i derived a new Class "Node" from QGraphicsItem which stores a pointer to the corresponding QTreeWidgetItem. I find out my selected QGraphicsItem by calling view->scene()->selectedItems(), how can i get the stored pointer now? Because this function just returns me items of the base class QGraphicsItem.

    What i could do, is to reimplement the setSelected function in my class "Node" and call the QTreeWidget::setCurrentItem() with the stored pointer from there. is that the way to go? cause it doesnt seem to work... isnt the QGraphicsView calling the setSelected() function on an Item, if you click on it in the view (its flag is set to QGraphicsItem::ItemIsSelectable)?
    Last edited by Cal; 20th November 2009 at 14:01.

  3. #3
    Join Date
    Sep 2009
    Posts
    140
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    4
    Thanked 17 Times in 17 Posts

    Default Re: How to communicate btw QGraphicsScene and QTreeWidget

    Since your have got 2 views that are reflecting the selection, is it not better to use a model, and manage some Ids for your items instead of pointers directly?

    Then, each view cans have a map of [Id, item] to manage selection.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.