Results 1 to 8 of 8

Thread: QTreeWidget and Graphics scene

  1. #1
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QTreeWidget and Graphics scene

    I have a QTreeWidget which shows data about graphics items and top level items are like groups which have different graphics items... attaching a snapshot of the treewidget.

    The tree displays info about items positions and names... I want to update the tree when items are moved (as items pos is displayed in the tree). How do I map the nodes of tree to the GraphicsItems ?? I mean how do i obtain a pointer to the GraphicsItem based on the node clicked in the tree ?? and how to refresh the data in the tree based on movements in the scene ??

    One method I found in the search forums was to subclass QTreeWidgetItem and have the desired info in it...is it a good one ??

    Please suggest...
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidget and Graphics scene

    The proper way would be to use your own model and keep a pointer to the graphics item in the model index. But if you want to stick with the treewidget approach, then you can make a QMap<QTreeWidgetItem*, QGraphicsItem*> map and hold the info there.

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: QTreeWidget and Graphics scene

    The proper way would be to use your own model and keep a pointer to the graphics item in the model index
    I tried to read about models, and right now its going over my head.
    Also I need a tree with single column, so I am not sure to go in for a model for this... there must be a simple way
    But if you want to stick with the treewidget approach, then you can make a QMap<QTreeWidgetItem*, QGraphicsItem*> map and hold the info there.
    I cud have used this approach, but not all treeWidgetItems are related to GraphicsItem, like the PL.. it contains a list of graphicsitems which are contained in it.

    Also in future I may need to add tree nodes based on certain lists and not graphicsitems..

    and the subclassing QTreewidgetItem idea was given by you(wysota) in this thread

    what say ??

    Also I would be glad if u teach me something about the model , model/view architecture in context with this prpblem, I searched thru Qt Examples but cudnt find a suitable example related to my problem.. only if experts like u speak something, it wud be a great speed up for guys like me

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidget and Graphics scene

    Quote Originally Posted by aamer4yu View Post
    I tried to read about models, and right now its going over my head.
    It's better to switch to the model approach sooner than later, you'll have less rewriting to do

    For the beginning you can cheat a little, use QStandardItemModel and either create a custom item role which will hold a pointer to a graphicsview item or reimplement the index() method of the model and store the pointer as the internal pointer. The latter solution is better, but it'll only work if QStandardItemModel doesn't use that internal field for itself.

    Also I need a tree with single column, so I am not sure to go in for a model for this... there must be a simple way
    The point is that you don't want to do simple things, so you shouldn't use simple solutions.

    I cud have used this approach, but not all treeWidgetItems are related to GraphicsItem, like the PL.. it contains a list of graphicsitems which are contained in it.
    Does it matter? You only store there what you like.

    Also in future I may need to add tree nodes based on certain lists and not graphicsitems..
    That's another argument for using a full featured model.

    Also I would be glad if u teach me something about the model , model/view architecture in context with this prpblem, I searched thru Qt Examples but cudnt find a suitable example related to my problem.. only if experts like u speak something, it wud be a great speed up for guys like me
    When I find some tme (during Christmas maybe?) I'll post an example model made from scratch on my website (in the GL model article series), so you'll be able to take a look.

  5. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: QTreeWidget and Graphics scene

    Thanks for the reply...
    Currently I am making a prototype of an application which I have to make later on.. and need to finish it soon....
    so I guess implementing the model will take time and i wont be able to meet the deadlines in meantime I have to stick to some shortcuts
    I can explore optimising things later for the main project....

    When I find some tme (during Christmas maybe?) I'll post an example model made from scratch on my website (in the GL model article series), so you'll be able to take a look.
    I will be waiting for it eagerly...
    Thanx again

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidget and Graphics scene

    Quote Originally Posted by aamer4yu View Post
    Currently I am making a prototype of an application which I have to make later on.. and need to finish it soon....
    It takes not more than an hour to implement a simple model.
    so I guess implementing the model will take time and i wont be able to meet the deadlines in meantime I have to stick to some shortcuts
    Sure, just make sure the shortcuts are really shorter than the full-featured solution

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget and Graphics scene

    It takes not more than an hour to implement a simple model.
    an hour for you ?? i wonder how long it will take for me..

    jokes apart,,, i will try if u say so... can u give some steps regarding the same..
    and yeah, I will be waiting for ur example
    Thx

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidget and Graphics scene

    Quote Originally Posted by aamer4yu View Post
    an hour for you ?? i wonder how long it will take for me..
    You can start by modifying the simple tree model example. It'll take you 10 minutes then

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.