Here's an example. One thing to note, which may be why you are having a problem in the first place: QListView only supports *one* column. If you want more than one column, you need to use QTableView or QTreeView.
#include <QtGui/QApplication>
#include <QTableView>
#include <QStandardItemModel>
#include <QList>
int main(int argc, char *argv[])
{
model.setColumnCount( 2 );
for ( int nItem = 0; nItem < 10; ++nItem )
{
model.appendRow( items );
}
view.setModel( &model );
view.show();
return a.exec();
}
#include <QtGui/QApplication>
#include <QTableView>
#include <QStandardItemModel>
#include <QList>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTableView view;
QStandardItemModel model;
model.setColumnCount( 2 );
QStandardItem * item;
for ( int nItem = 0; nItem < 10; ++nItem )
{
QList< QStandardItem * > items;
items << new QStandardItem( QString( 'A' + nItem ) );
items << new QStandardItem( QString::number( nItem * 10 + 10 ) );
model.appendRow( items );
}
view.setModel( &model );
view.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
The attached screnshots show table and tree views; all I did was change the view type from QTableView to QTreeView.
Table.png Tree.png
Bookmarks