Results 1 to 7 of 7

Thread: Modify model data in QTreeView

  1. #1
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    63
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Modify model data in QTreeView

    Hello !

    I subclassed QItemDelegate, QAbstractItemModel in order to build tree model and see data in QTreeView. Now I need to modify model data, do I have to subclass QTreeView or I can achive it using QTreeView ?
    Best regards,
    Yuriy Rusinov.

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Modify model data in QTreeView

    Quote Originally Posted by YuriyRusinov View Post
    Hello !

    I subclassed QItemDelegate, QAbstractItemModel in order to build tree model and see data in QTreeView. Now I need to modify model data, do I have to subclass QTreeView or I can achive it using QTreeView ?

    I tested to subclass the item :-( is not easy!
    I found a way to make a xml file tree unlimited .... and on a simple class i manage
    the domelement & QTreeWidgetItem & the level of tree....

    each new Item i add on aa QList<OneTree*> niagaratree; xxx.additem(**) an so i can interact on 2 class... on add item remove rename ecc... on QDomElement you can save all data image html page e other ..on.. QDomElement like a oracle DB :-)....

    to delete on item i save the Nr of tree ... and fast save the file xml + reload the GUI whitout the delete nr..item ...

    Is moore simple way... and fast....


    Qt Code:
    1. QList<OneTree*> niagaratree;
    2. typedef QMap<QString, QString> Treevar;
    3.  
    4. class OneTree : public QObject, public Base_Function
    5. {
    6. Q_OBJECT
    7.  
    8. public:
    9. OneTree( QDomElement d , QTreeWidgetItem * top , int lev );
    10. ...............
    11. private:
    12. .....
    13. signals:
    14. void SendtonewDom(int);
    15. void SendtoParent(QString);
    16. public slots:
    17. void MoveToNewDest()
    18. {
    19. /////qDebug() << "### ONLISTER emit start " << ONLISTER;
    20. emit SendtonewDom(ONLISTER);
    21. }
    22.  
    23. };
    To copy to clipboard, switch view to plain text mode 
    Last edited by patrik08; 26th October 2006 at 12:51.

  3. #3
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    63
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Modify model data in QTreeView

    That I have to make view classes, which inherits QTreeView ?
    Best regards,
    Yuriy Rusinov.

  4. #4
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Modify model data in QTreeView

    Quote Originally Posted by YuriyRusinov View Post
    That I have to make view classes, which inherits QTreeView ?
    ??? QTreeWidget or QTreeView equal exept model ...
    change the model is not evry time the better way ....
    change the access mode can bring the same result.... only the way is long or briefly...

    IMO: I found access is not long....

  5. #5
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    63
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Modify model data in QTreeView

    OK, I'll process signal clicked() on QTreeView and make editor events. Thanks.
    Best regards,
    Yuriy Rusinov.

  6. #6
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Modify model data in QTreeView

    Quote Originally Posted by YuriyRusinov View Post
    OK, I'll process signal clicked() on QTreeView and make editor events. Thanks.

    If You like grab the first structure from Tree Category

    http://ppk.ciz.ch/win_build/tree_cat_memo/Tree_Cat.zip

    & + the idea of class OneTree you can associate 100 of attribute each single node....



    to test right click and insert node sets...
    this sample code replace on old Nested Sets mysql from an old cms Category manager... same as ....
    http://www.klempert.de/nested_sets/demo/

  7. The following user says thank you to patrik08 for this useful post:

    YuriyRusinov (26th October 2006)

  8. #7
    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: Modify model data in QTreeView

    Quote Originally Posted by YuriyRusinov View Post
    I subclassed QItemDelegate, QAbstractItemModel in order to build tree model and see data in QTreeView. Now I need to modify model data, do I have to subclass QTreeView or I can achive it using QTreeView ?
    You can achieve it with QTreeView. The view is just for displaying data and you want to change the data itself - the model. Editing model data is a responsibility of item delegate - it calls setData() on the model where appropriate, just make sure your model can handle setData() calls. If you take a look at QItemDelegate - there are createEditor, setEditorData and setModelData methods. They are responsible for edition. You can reimplement them if the default implementations don't suit your needs (but maybe they do, check that out). Just make sure data in your model is editable (return ItemIsEditable if flags() for each index you want editable) and set proper triggers in the view using QAbstractItemView::setEditTriggers().

  9. The following user says thank you to wysota for this useful post:

    YuriyRusinov (27th October 2006)

Similar Threads

  1. hierarchical model in a flat view
    By gniking in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 20:17
  2. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53
  3. Model, view, resize to show all data
    By jcr in forum Qt Programming
    Replies: 2
    Last Post: 17th April 2006, 20:59
  4. how to use QTreeView with Database model
    By mikro in forum Newbie
    Replies: 3
    Last Post: 13th April 2006, 16:12
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.