PDA

View Full Version : how to set QComboBox on qsqlquerymodel header



sivamuthaiah
21st July 2009, 06:35
Hi,

I need to show the combobox widget on a qsqlquerymodel header. (in the second column header)
In my code i overrided the headerData() method.
But combobox is not coming.Its showing empty.

My Code,


UserQueryModel *model = new UserQueryModel (ui.table);//derived from qsqlquerymodel class
model->setQuery("select * from sf_search");
ui.table->setModel(model);


class UserQueryModel:public QSqlQueryModel
{
public:
QTableView *mTable;
QVariant variant;
QWidget widget;

UserQueryModel(QTableView *table)
{
mTable = table;

QHBoxLayout *layout = new QHBoxLayout(&widget);
QComboBox *box = new QComboBox(&widget);
layout->addWidget(box);
variant.setValue(&widget);

}

QVariant headerData( int section, Qt::Orientation orientation, int role) const
{
if(section == 2 && (orientation == Qt::Horizontal))
{
return variant;
}
return QSqlQueryModel::headerData(section, orientation, role);
}

Can somebody help me with this??