PDA

View Full Version : How to allow for multiple combo boxes with a database and QT



melrad187
4th May 2010, 07:49
I am trying to get allow the user the select critieria from multiple combo boxes using a database. Each combo box has to have a connection for the change of index in each selection box. How can I get the second combo box to use the results of the first instead of the overall rockTable. I have tried many things, and can not seem to find much information about how do this anywhere. I have 9 selection boxes and I want each to work of the previous. I am using QSqlRelationTableModel

setting table

model = new QSqlRelationalTableModel(this);
model->setTable(Table);
model->setRelation(2, QSqlRelation(colorTable, "idc", "color"));
model->select();


changing color for selection box

void MainWindow::changeColor(int row) // row for combo box
{
if (row > 0) {
QModelIndex index = model->relationModel(2)->index(row, 1);
model->setFilter("color = '" + index.data().toString() + '\'');
} else if (row == 0) { // if row == 0 then display all
model->setFilter(QString());
} else {
return;
}
}


setting up the color combo box

colorView = new QComboBox;

// set what column to use in the combo box (this one is color)

colorView->setModel(model->relationModel(2));
colorView->setModelColumn(1);

// signal is the index changing (user action)
// slot is the change color function (result of action)

connect(colorView, SIGNAL(currentIndexChanged(int)),
this, SLOT(changeColor(int))

all the rest of the other boxes are the done the same exept the relationModel changes by on for each box. Does anyone
have any ideas of how to do this. Or have any iformation on this.

Thank You