Results 1 to 4 of 4

Thread: Manage correctly QListView item

  1. #1
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60 Maemo/MeeGo

    Smile Manage correctly QListView item

    Hi,
    I'm new to qt
    I started some day ago with qt, setting up Eclipse CDT with qt plugin on a Linux Ubuntu 10.04 computer.
    After some test with the library and reading some documentation on the net like http://doc.qt.nokia.com/4.7/model-view-programming.html I started to make some experiment with QListView.

    The problem now is..
    I'm able to manage insert and remove of QString inside the QListView.

    But how can I put/get Generic Object with my choosen rappresentation?

    For example:

    class MyCustomElement {
    private:
    int index;
    string name;
    string surname;
    };

    How can I put some MyCustomElement Object inside a ListView?
    Do I need to inherit from this http://doc.qt.nokia.com/4.7/qabstractitemmodel.html MyCustomElement ?
    Should I use a TableView instead of a ListView?
    Thanks you

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Manage correctly QListView item

    It depends on what you want to hold in the model and how you want to show it. If you want to show a table, use QTableView. If you only want to show a list, use QListView. You can create a new model based on QAbstractTableModel, QAbstractListModel and on QAbstractItemModel. The latter of which will be most involved, as you will have to implement most of it yourself. The nature of the model view framework is so that you can use any type of view on any type of model.

    To answer your question: Implement a model and add it to the view. You shouldn't have to do any work on the view.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

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

    noct (22nd November 2010)

  4. #3
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60 Maemo/MeeGo

    Default Re: Manage correctly QListView item

    Hi,
    I have implemented an QAbstractListModel and I used it for manage the element inside a ListView.
    Now I had another problem.
    I have 2 ListView:
    - the first list is full of element
    - the second list is empty
    I also have an addButton and I defined a signal/slot for it.
    How can I move the selected object from the first list , to the second?
    Thanks you

  5. #4
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Manage correctly QListView item

    Copy data from m1, remove data from m1, paste data in m2. You could have a look at some item view examples and drag 'n' drop examples.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

Similar Threads

  1. Item width in QListView
    By bepaald in forum Qt Programming
    Replies: 0
    Last Post: 17th August 2010, 13:42
  2. Expand item in QListView
    By Kode.Cooper in forum Qt Programming
    Replies: 5
    Last Post: 30th December 2009, 08:22
  3. QListview set selected item
    By Freeman551 in forum Qt Programming
    Replies: 1
    Last Post: 25th December 2009, 00:17
  4. Add new item to a QListView
    By graciano in forum Newbie
    Replies: 2
    Last Post: 18th August 2009, 18:49
  5. how to move item up and down in QListView
    By zhanglr in forum Qt Programming
    Replies: 3
    Last Post: 1st August 2008, 14:39

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.