开发者

dynamically add rows to tableview

I want to have a table view in my Qt code. It has four column and many rows (not know ) 开发者_如何转开发before hand in table view Qt how can I dynamically add rows as

QStandardItemModel model(0,2);

What to do add rows dynamically?


there is a huge set of functions for that ,

void    appendColumn ( const QList<QStandardItem *> & items )
void    appendRow ( const QList<QStandardItem *> & items )
void    appendRow ( QStandardItem * item )
void    insertColumn ( int column, const QList<QStandardItem *> & items )
bool    insertColumn ( int column, const QModelIndex & parent = QModelIndex() )
void    insertRow ( int row, const QList<QStandardItem *> & items )
bool    insertRow ( int row, const QModelIndex & parent = QModelIndex() )
void    insertRow ( int row, QStandardItem * item )

look in qt docs for their description

UPD:

QStandardItemModel m(3,3);
QList<QStandardItem*> newRow;
for (int i=0;i<m.colCount();i++)
{
    QStandardItem* itm = new QStandardItem(QString("data for col %1").arg(i));
    newRow.append(itm);
}
m.append(newRow);

haven't test it but it should work

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜