Can I add columns in a QListView in Qt?

浪子不回头ぞ 提交于 2019-12-24 13:08:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!