Results 1 to 9 of 9

Thread: Which Common Model can be used for Tree View Display and List View Display ?

  1. #1
    Join Date
    Mar 2010
    Posts
    22
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Which Common Model can be used for Tree View Display and List View Display ?

    Hi

    I want to create a Model which stores Data and displays in both TreeView and Lsit View Format. What is the best way to go about it. Do I use some Standard model or Subclass some existing. Also I want to customize the way the data columns are to be stored. Please Reply or Guide me to some thread if already existing

    Thanks a lot

  2. #2
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Which Common Model can be used for Tree View Display and List View Display ?

    I think that depends on src data, if "layout/structure" of it is in table meaner so it's only natural to go wit TableModel. Also If you need some special/custom functionality subclassing model is a way to go.
    For example, here is a QStandardItemModel with different views.

    Snap4..jpg Snap1..jpg Snap3..jpg

    As you can see I used ComboBox/ListView(icon mode) / TableView and everything looks nice. I stored data and setup views to display data that is needed at the time. I prepared in advance (when populating model) all the data that I need and only retrieve them when needed.
    Also, when adding data to the model, You can specify the role that data can perform, so View know how to handle them, i.e. for QImage I added QtecorationRole, and for QString Qt:isplayRole so views know haw to process them.

    I hope this shed some light of the subject
    Regards.

  3. #3
    Join Date
    Mar 2010
    Posts
    22
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Which Common Model can be used for Tree View Display and List View Display ?

    Hey Talei ..
    thanks a lot for your reply

    The Problem for me is I want to use a Single model for Tree View Display as Well as List View Display
    So when I do this, I am unable to see the child items in the List View which I created using Standard Model. Only parent Items are dispalyed
    e.g

    Display in Tree View:
    A
    b
    C
    d
    When I do a List View display of Same, I only see
    A
    C

    Whereas I would like to do some filtering to display
    b
    d

    Thanks

  4. #4
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Which Common Model can be used for Tree View Display and List View Display ?

    Does b/d are another column in Your model? If so it seams that You listView display only colum 0, with is default, simply use:
    Qt Code:
    1. listView->setModelColumn( 1 );
    To copy to clipboard, switch view to plain text mode 
    or any other column number, that you want to display. ListView displays only one column in view.

  5. #5
    Join Date
    Mar 2010
    Posts
    22
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Which Common Model can be used for Tree View Display and List View Display ?

    No they are not another column, they are rows which are children of A and C.

    The display Got Formatted in last post, Actual Tree View is :
    A
    (Tab)b
    C
    (Tab)d

    This is how I am creating the Model:

    QStandardItemModel *Treemodel = new QStandardItemModel(0,1);

    QStandardItem* item1 = new QStandardItem("A");
    QStandardItem* item2 = new QStandardItem("C");

    QStandardItem* item3 = new QStandardItem("b");
    QStandardItem* item4 = new QStandardItem("d");

    item1->appendRow(item3);
    item2->appendRow(item4);

    So, a TreeVIew for this Model displays all items but A ListView only displays A and C. I want all of them to be displayed on which I can apply some filter to show only Children
    Thanks
    Last edited by abk883; 4th May 2010 at 12:04.

  6. #6
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Which Common Model can be used for Tree View Display and List View Display ?

    AFAIK in your current implementation You can't do that, because ListView is one-dimensional list (that's why You can see item1/2, they are parents for children items), so there is, AFAIK "no way" to display 2d matrix. Workaround would be to create 1D list, but You will loose all hierarchy information that way.
    Also if You want to show only children in ListView, you can traverse through all parents items (item1/2), build model and display only that in ListView.

  7. #7
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Which Common Model can be used for Tree View Display and List View Display ?

    Your treemodel will index every element added to the tree.

    For any given item in the tree you can get the other elements at the same level using the sibling function.

    For more info take a look at the documentation for QModelIndex.

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,688
    Thanks
    13
    Thanked 1,598 Times in 1,526 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Which Common Model can be used for Tree View Display and List View Display ?

    Store your data in a basic table model with a the hierarchy you want for your tree view. If the children you want to show in your list view are all of the same parent then you might consider using a single-columned tree view and QTreeView::setRootIndex(). If not, as would seem to be the case in your example, write a QAbstractItemProxyModel derivative to filter the underlying table to produce a single-columned list for your list view.

    I think the browser example in the Qt distribution/demos contains an implmentation described here http://labs.trolltech.com/blogs/2008...-of-modelview/

  9. #9
    Join Date
    Mar 2010
    Posts
    22
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Which Common Model can be used for Tree View Display and List View Display ?

    Thanks a lot guys.... Tried a bit but the solution seems to be somewhat complex ..Going with a Two Model Strategy right now and will try on the suggestion again
    sometime later .

Similar Threads

  1. Replies: 33
    Last Post: 7th December 2009, 11:11
  2. How to map tree model data to list view
    By msopanen in forum Qt Programming
    Replies: 0
    Last Post: 10th November 2009, 20:56
  3. Problems to display a QFont in a View/Model correctly
    By NoRulez in forum Qt Programming
    Replies: 0
    Last Post: 8th July 2009, 13:26
  4. Replies: 1
    Last Post: 16th January 2008, 12:48
  5. Model-view: Display items in different ways
    By taboom in forum Qt Programming
    Replies: 3
    Last Post: 13th August 2007, 20:05

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.