问题
Can I add columns in a QListView object??
here's something I found here:
model->setHeaderData( 0, Qt::Horizontal, "numéro" );
model->setHeaderData( 1, Qt::Horizontal, "prénom" );
model->setHeaderData( 2, Qt::Horizontal, "nom" );
//...
model->setData( model->index( line, 0 ), contact->num(), Qt::DisplayRole );
model->setData( model->index( line, 1 ), contact->prenom(), Qt::DisplayRole );
model->setData( model->index( line, 2 ), contact->nom(), Qt::DisplayRole );
Since I'm using Qt Creator 2.0.1, I figured my model would be:
ui->ObjectName->model()
The Code snippet was added in the main window constructor's implementation after the:
ui->setupUi(this);
The application builds successfully but I get a: "The program has unexpectedly finished." at runtime.
Any Ideas ? Thanks.
回答1:
I don't believe QListView supports multiple columns. You can use a QTreeWidget instead, it supports multiple columns.
来源:https://stackoverflow.com/questions/4506817/can-i-add-columns-in-a-qlistview-in-qt