Kyef
22nd July 2015, 14:25
I have searched and I have not found any valid solutions to my problem with QSortFilterProxyModel. I am asking in the same line with this thread
(http://www.qtcentre.org/threads/27877-QSortFilterProxyModel-and-QSqlRelationalDelegate-in-TableView) and another one here (http://www.qtcentre.org/threads/46930-QSqlRelationalTableModel-with-QSortFilterProxyModel-and-SqlRelationalDelegate) which where not answered. I need to filter the output on my tableview but also be able to edit the columns however, when QSortFilterProxyModel is called, I loose focus of the comboboxes. Is there a work around on this? Bellow is my code
void clsList::strModel()
{
strmodel = new QSqlRelationalTableModel(this);
strmodel->setEditStrategy(QSqlTableModel::OnRowChange);
strmodel->setTable("setCls_str");
strmodel->setFilter("setCls_str.actv1=1");
int clInd = strmodel->fieldIndex("classCode");
int strInd = strmodel->fieldIndex("streams");
int clTInd = strmodel->fieldIndex("clTeach");
strmodel->setRelation(clInd, QSqlRelation("tblClass", "clID", "clCode"));
strmodel->setRelation(strInd, QSqlRelation("tblStreams", "strID", "strName"));
strmodel->setRelation(clTInd, QSqlRelation("allTeachers", "trID", "trName"));
strmodel->setHeaderData(strInd, Qt::Horizontal, tr("Stream"));
strmodel->setHeaderData(clInd, Qt::Horizontal, tr("Class"));
strmodel->setHeaderData(clTInd, Qt::Horizontal, tr("Teacher"));
strmodel->database().transaction();
if(strmodel->submitAll())
{
strmodel->database().commit();
}
else
{
strmodel->database().rollback();
}
if (!strmodel->select()) {
showError(strmodel->lastError());
return;}
strProxy = new SortFilterProxyModel(this);
strProxy->setSourceModel(strmodel);
strProxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
ui->strmv->setModel(strProxy); // with this line all comboboxes disappear on my tableview
// ui->strmv->setModel(strModel); // This line works well....with comboboxes visible on the grid
//but I need to filter data according to some parameters
ui->strmv->setItemDelegate(new QSqlRelationalDelegate(ui->strmv));
ui->strmv->setColumnWidth(clInd,50);
ui->strmv->setColumnWidth(strInd,100);
ui->strmv->setColumnWidth(clTInd,100);
}
(http://www.qtcentre.org/threads/27877-QSortFilterProxyModel-and-QSqlRelationalDelegate-in-TableView) and another one here (http://www.qtcentre.org/threads/46930-QSqlRelationalTableModel-with-QSortFilterProxyModel-and-SqlRelationalDelegate) which where not answered. I need to filter the output on my tableview but also be able to edit the columns however, when QSortFilterProxyModel is called, I loose focus of the comboboxes. Is there a work around on this? Bellow is my code
void clsList::strModel()
{
strmodel = new QSqlRelationalTableModel(this);
strmodel->setEditStrategy(QSqlTableModel::OnRowChange);
strmodel->setTable("setCls_str");
strmodel->setFilter("setCls_str.actv1=1");
int clInd = strmodel->fieldIndex("classCode");
int strInd = strmodel->fieldIndex("streams");
int clTInd = strmodel->fieldIndex("clTeach");
strmodel->setRelation(clInd, QSqlRelation("tblClass", "clID", "clCode"));
strmodel->setRelation(strInd, QSqlRelation("tblStreams", "strID", "strName"));
strmodel->setRelation(clTInd, QSqlRelation("allTeachers", "trID", "trName"));
strmodel->setHeaderData(strInd, Qt::Horizontal, tr("Stream"));
strmodel->setHeaderData(clInd, Qt::Horizontal, tr("Class"));
strmodel->setHeaderData(clTInd, Qt::Horizontal, tr("Teacher"));
strmodel->database().transaction();
if(strmodel->submitAll())
{
strmodel->database().commit();
}
else
{
strmodel->database().rollback();
}
if (!strmodel->select()) {
showError(strmodel->lastError());
return;}
strProxy = new SortFilterProxyModel(this);
strProxy->setSourceModel(strmodel);
strProxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
ui->strmv->setModel(strProxy); // with this line all comboboxes disappear on my tableview
// ui->strmv->setModel(strModel); // This line works well....with comboboxes visible on the grid
//but I need to filter data according to some parameters
ui->strmv->setItemDelegate(new QSqlRelationalDelegate(ui->strmv));
ui->strmv->setColumnWidth(clInd,50);
ui->strmv->setColumnWidth(strInd,100);
ui->strmv->setColumnWidth(clTInd,100);
}