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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.