show User Defined Header Labels in QTableView
Hello every one i have a QTableView in which i am displaying data from the sql database.. I am stuck at a small problem i wanted to display Header names for all the channel's which i have appended in a QStringList. I tried many things but i get the database table column name's as the header's.
Code:
model->setQuery("SELECT "+ colNames +" from thdata where rowid = (select max(rowid) from thdata)");
tableView->setModel(model);
tableView->showMaximized();
tableView->setAlternatingRowColors(true);
//tableView->setHorizontalHeader(thermoNames);
//tableView->setHorizontalHeaderLabels(QString(thermoNames));
tableView->resizeRowsToContents();
tableView->resizeColumnsToContents();
timeinterval.clear();
tableView->verticalHeader()->setVisible(false);
colNames.clear();
this is what i am doing to display all the channels data from the database table, but the header is the column names in the Table i wanted to display the header names which i have defines and stored in a QString thermoNames; , Pls help me out.
Thank you
Re: show User Defined Header Labels in QTableView
I wanted to put the Header Names which i have defined on the Top Horizontal Header, instead of the horizontal header names which are column names of the sql table. . i have all the names which i want in a QStringList. i looked a lot but din find a solution. .. can any one pls tell me how to go about it.
Re: show User Defined Header Labels in QTableView
setHorizontalHeaderLabels requires a QStringList, furthermore make sure you set the labels after the model is populated. And I guess you have to set the labels everytime you change the query.
EDIT: or make it, like the documentation tells:
Code:
model->setQuery("SELECT name, salary FROM employee");
model->setHeaderData(0, Qt::Horizontal, tr("Name"));
model->setHeaderData(1, Qt::Horizontal, tr("Salary"));
view->setModel(model);
view->show();
Re: show User Defined Header Labels in QTableView
Hello Lykurg your example helped me solve my problem.. This is what i did to display the Header Labels which i have defined.
Code:
for(int i=0; i<thermoNames.count(); i++)
{
model->setHeaderData( i, Qt::Horizontal,thermoNames.at(i));
}
thank you