Results 1 to 6 of 6

Thread: Exploring the items of a QtreeWidget using its model

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Exploring the items of a QtreeWidget using its model

    I have a QtreeWidget, and I want to 'explore' it using it model data.
    I have a vector<QStandardItemModel*>. First I add the main model for the tree.
    I explore it and add new models to my vector if I find nodes with children.
    ( I think that with a simple code I can transverse the whole tree).

    Ok, now I have :
    Qt Code:
    1. tree_model= (QStandardItemModel*)QTreeWidget->model();
    2. tree_model->rowCount();
    3. tree_model->columnCount();
    To copy to clipboard, switch view to plain text mode 

    But I dont know how to get the 'node' data. (text and datamodel)
    I have to use a modelIndex?
    Qt Code:
    1. QModelIndex mi = tree_model>index(row, col); ???
    To copy to clipboard, switch view to plain text mode 
    But I could to use:
    Qt Code:
    1. tree_model->item(row,col)->text();
    2. tree_model->item(row,col)->has_children;
    3. tree_model->item(row,col)->model()
    To copy to clipboard, switch view to plain text mode 

    But I have errors .... And I don find nothing useful at help reference
    Any help ? Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Exploring the items of a QtreeWidget using its model

    I have a vector<QStandardItemModel*>.
    Why?
    Why use a vector of models?
    How do you use multiple models on one tree?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Exploring the items of a QtreeWidget using its model

    The help reference for model-view is very poor.
    Finally I have found some useful at :
    http://developer.qt.nokia.com/wiki/Model_Test
    I think that is time for improve the QT reference help.
    Thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Exploring the items of a QtreeWidget using its model

    I disagree.
    Qt documentation is one of the best I know, and often people will explicitly point out how good the documentation is when they just come across Qt for the first time, specially when compared to other toolkits.
    I agree, that since 4.7, the quality of the documentation has suffered, I guess due to the large amount of added classes, and various other issues we all know that are going on at Nokia, never the less, I find the documentation still to be one of the best out there. (That doesn't mean it can't be improved!)
    Are you sure you read ALL there is in the documentation about Model/Viewer?
    http://doc.qt.nokia.com/latest/model...l#view-classes
    http://doc.qt.nokia.com/latest/modelview.html
    And this will be very much you case I think:
    http://doc.qt.nokia.com/latest/itemv...treemodel.html

    And these links are not all.
    As you can see, Model Viewe is VERY well documented, and I doubt you took the trouble to read all of that.
    And if I am wrong, and you did, I just can't follow on your conclusion...
    Last edited by high_flyer; 27th July 2011 at 09:48.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    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: Exploring the items of a QtreeWidget using its model

    If you have specific questions about ItemViews, then ask. Just be clear and explicit about what you want. Especially don't use ambiguous terms like "explore". I have no idea what "exploring a QTreeWidget" means. I would guess it was reading its documentation and playing around with its features but that's probably not what you meant.
    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.


  6. #6
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Exploring the items of a QtreeWidget using its model

    When I refer to the concept of improve the help I wanted to say the "QT Reference documentation" you can use inside QtCreator.
    It's time to make an upgrade of it with the information you can find on web,
    http://doc.qt.nokia.com/latest ...
    http://developer.qt.nokia.com/wiki/Model_Test
    ... etc.
    I think that it'd be neccesary to include this usefull information inside QT reference doc. The copyright note of it says 'nokia 2008 -2010'. (January or December?) .

    DIGIA has to do this work?

    I like QT but there is a few things related with the way you can learn QT & QTcreator that would have to be better.
    Thanks

Similar Threads

  1. removing items QTreeWidget
    By Mystical Groovy in forum Qt Programming
    Replies: 3
    Last Post: 25th March 2015, 21:58
  2. How to delete items in QTreeWidget...
    By Patrick Sorcery in forum Newbie
    Replies: 12
    Last Post: 10th September 2010, 09:41
  3. The order of items in QTreeWidget
    By KK in forum Qt Programming
    Replies: 4
    Last Post: 27th February 2009, 04:54
  4. amount of items in QTreeWidget
    By supergillis in forum Qt Programming
    Replies: 4
    Last Post: 1st August 2008, 22:38
  5. Replies: 2
    Last Post: 17th March 2008, 12:53

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.