I have a QTableWidget with QComboBoxs in row 0. External events will trigger changes to row zero--I was going to copy row 0 using the data associated with each comboboxes currentItem into a new row in the table.
Right now, I get the QTable created with row 0 having the ComboBoxes. I can addItems for each combobox when the external event occurs with no issues.
However, I wanted one of the columns to NOT have a QComboBox, but just a regular cell. But, when I don't do a setCellWidget on column 0, I get an exception when trying to add an item to the column 1 combobox.
I tried using a QLabel for the cell widget for the column 0, row 0 cell and have the same problem.
Is this expected? Maybe if one cell has a widget, all cells in the table must use the same widget?
Here are the relevant code snippets.
In constructor:
// No widget desired in column 0
//runOrder->setCellWidget(0,0,new QLabel);
// Comboboxes in columns 1 through seven of row 0
for (int i=1;i<7;i++)
{
runOrder->setCellWidget(0,i, qb);
connect(qb, SIGNAL(currentIndexChanged(int)), this,SLOT(check_lineup(int)));
}
// Comboboxes in columns 1 through seven of row 0, not column 0
for (int i=1;i<7;i++)
{
runOrder->setCellWidget(0,i, qb);
connect(qb, SIGNAL(currentIndexChanged(int)), this,SLOT(check_lineup(int)));
}
// No widget desired in column 0
runOrder->setItem(0,0, new QTableWidgetItem);
//runOrder->setCellWidget(0,0,new QLabel);
// Comboboxes in columns 1 through seven of row 0
for (int i=1;i<7;i++)
{
QComboBox *qb = new QComboBox;
runOrder->setItem(0,i, new QTableWidgetItem);
runOrder->setCellWidget(0,i, qb);
connect(qb, SIGNAL(currentIndexChanged(int)), this,SLOT(check_lineup(int)));
}
// Comboboxes in columns 1 through seven of row 0, not column 0
for (int i=1;i<7;i++)
{
QComboBox *qb = new QComboBox;
runOrder->setItem(0,i, new QTableWidgetItem);
runOrder->setCellWidget(0,i, qb);
connect(qb, SIGNAL(currentIndexChanged(int)), this,SLOT(check_lineup(int)));
}
To copy to clipboard, switch view to plain text mode
In the code that adds entries to the comboboxes:
//Loop through the columns of row zero that have comboBoxes
for (int i=1;i<5;i++)
{
QComboBox * qb
= dynamic_cast<QComboBox
*>
(runOrder
->cellWidget
(0,i
));
qb->clear();
//Loop through the lineup
for (int j=0;j<5;j++)
{
QString dog_name
= lineup_query.
value(j
).
toString();
qb->addItem(dog_name);
}
qb->setCurrentIndex(i);
}
If I change
// Comboboxes in columns 1 through seven of row 0
for (int i=1;i<7;i++)
{
runOrder->setCellWidget(0,i, qb);
connect(qb, SIGNAL(currentIndexChanged(int)), this,SLOT(check_lineup(int)));
}
//Loop through the columns of row zero that have comboBoxes
for (int i=1;i<5;i++)
{
QComboBox * qb = dynamic_cast<QComboBox *>(runOrder->cellWidget(0,i));
qb->clear();
//Loop through the lineup
for (int j=0;j<5;j++)
{
QString dog_name= lineup_query.value(j).toString();
qb->addItem(dog_name);
}
qb->setCurrentIndex(i);
}
If I change
// Comboboxes in columns 1 through seven of row 0
for (int i=1;i<7;i++)
{
QComboBox *qb = new QComboBox;
runOrder->setItem(0,i, new QTableWidgetItem);
runOrder->setCellWidget(0,i, qb);
connect(qb, SIGNAL(currentIndexChanged(int)), this,SLOT(check_lineup(int)));
}
To copy to clipboard, switch view to plain text mode
to loop from 0 to 7, everything seems to work fine, except I get a comboBox in column zero I really don't want.
Thanks,
Dave Thomas
Bookmarks