Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically adding rows to tableview

Tags:

c++

qt

I want to have a table view in Qt. It has four column and "n" rows at the start in table view. How can I dynamically add rows?

like image 610
sajid Avatar asked Oct 14 '25 17:10

sajid


1 Answers

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

like image 70
Raiv Avatar answered Oct 17 '25 07:10

Raiv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!