Results 1 to 4 of 4

Thread: QAbstractItemModel to different views

  1. #1
    Join Date
    Feb 2008
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default QAbstractItemModel to different views

    Hi,

    I need to display the data from QAbstractItemModel to different views say to Treeview and list view. QAbstractItemModel contains a QList of structs. And struct has marks of students for 6 subjects. The Treeview should display sum of all marks, and ListView will have 6 columns and has to display each marks in separate columns. What is the best way i can do this?

    Tree view sample
    - marks
    +-- 80
    +-- 90


    List view sample
    col1 | col2 | col3 | col4 | col5 | col6
    --------------------------------------------------
    10 | 20 | 10 | 20 | 10 | 10
    10 | 20 | 10 | 20 | 10 | 20

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QAbstractItemModel to different views

    Quote Originally Posted by ganeshshenoy View Post
    Hi,
    Hi

    I need to display the data from QAbstractItemModel to different views say to Treeview and list view. QAbstractItemModel contains a QList of structs. And struct has marks of students for 6 subjects. The Treeview should display sum of all marks, and ListView will have 6 columns and has to display each marks in separate columns.
    QListView cannot handle multiple columns so in fact both will be tree views.

    What is the best way i can do this?

    Tree view sample
    - marks
    +-- 80
    +-- 90


    List view sample
    col1 | col2 | col3 | col4 | col5 | col6
    --------------------------------------------------
    10 | 20 | 10 | 20 | 10 | 10
    10 | 20 | 10 | 20 | 10 | 20
    Put a proxy model in between which makes it flat. Something like FlatProxyModel at http://www.thorsen-consulting.dk/freebies.html.
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    ganeshshenoy (19th February 2008)

  4. #3
    Join Date
    Feb 2008
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QAbstractItemModel to different views

    Having tree view in both the case is a good idea. My model returns (thru data function) the sum of the marks. How can send for first view the sum and for the second view the individual marks. Or is there any other way where view can manipulate this?

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QAbstractItemModel to different views

    A model cannot return different data for different views. Therefore you must put a proxy model of some kind between model and either view.
    J-P Nurmi

Similar Threads

  1. Replies: 1
    Last Post: 16th January 2008, 11:48
  2. Once more : QAbstractItemModel woes
    By Valheru in forum Qt Programming
    Replies: 10
    Last Post: 15th January 2008, 10:44
  3. Replies: 4
    Last Post: 20th September 2007, 13:11
  4. Localizing date times in item views
    By jpn in forum Qt Programming
    Replies: 6
    Last Post: 6th February 2007, 14:47
  5. QAbstractItemModel for dummies
    By morty in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2006, 15:25

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.