PDA

View Full Version : Manage correctly QListView item



noct
22nd November 2010, 11:32
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

franz
22nd November 2010, 12:36
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.

noct
24th November 2010, 10:26
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

franz
26th November 2010, 08:34
Copy data from m1, remove data from m1, paste data in m2. You could have a look at some item view examples (http://doc.trolltech.com/latest/examples-itemviews.html) and drag 'n' drop examples (http://doc.trolltech.com/latest/examples-draganddrop.html).