Results 1 to 4 of 4

Thread: Models and item views

  1. #1
    Join Date
    Feb 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X
    Thanks
    1

    Default Models and item views

    Hi.

    I'm developing an application for managing contacts and other types of data. I've sub classed QAbstractItemView to make my ContactModel and I've got my contact list working with a QListView.

    I want to show a more detailed view of the contact when double clicked in the list and wonder how I would do that for a single item of the model. It seems to me like the models in Qt are made for lists of data rather than a row from the list.

    Thanks!

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

    Default Re: Models and item views

    Quote Originally Posted by gonemad View Post
    IIt seems to me like the models in Qt are made for lists of data rather than a row from the list.
    Not really. If you want to somehow display the data from the model then query the model for the data. How to do that depends how you implemented your model. If you used multiple columns to store the data then query columns of the row, if you have just one column but multiple roles holding the data then query the first column for the roles you need.
    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.


  3. #3
    Join Date
    Feb 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X
    Thanks
    1

    Default Re: Models and item views

    So the best way to do this, will be implementing user roles based on the fields I want to view?

    i.e
    Qt Code:
    1. ContactModel->data(index, ContactModel::NameField)
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Models and item views

    There is no single best way to do it. It all depends on your needs. Using custom roles is a good approach if you don't care about showing all the data in the view (at least not without implementing a custom delegate).
    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.


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

    gonemad (2nd March 2012)

Similar Threads

  1. Models, Views, and Styling
    By Goug in forum Qt Programming
    Replies: 2
    Last Post: 2nd December 2011, 04:29
  2. Problems with selection models & views
    By russdot in forum Qt Programming
    Replies: 3
    Last Post: 11th August 2009, 03:13
  3. list of custom item views?
    By Beluvius in forum Qt Programming
    Replies: 1
    Last Post: 29th March 2008, 06:43
  4. Models, delegates or views and how?
    By maddogg in forum Newbie
    Replies: 3
    Last Post: 9th November 2007, 13:59
  5. drag and drop with item views
    By castorvert in forum Qt Programming
    Replies: 14
    Last Post: 27th March 2006, 10:12

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
  •  
Qt is a trademark of The Qt Company.