如题
while(i {
QComboBox *combobox=new QCombobox();
combobox->addItem("1");
combobox->addItem("2");
ui->tabelwidget->setItem(i,j++,new QTabelWidgetItem(QString ID));
......
......
ui->tabelwidget->setItem(i,j++,new QTabelWidgetItem(combobox));
}
代码如上,怎样才能获取到combobox被点击时的当前行号,
菜比一枚,跪求指点,谢过!
connect(combobox, SIGNAL(currentIndexChanged(int)), SLOT(slot_comboboxIndexChanged(int)));
void slot_comboboxIndexChanged(int index)
{
QComboBox senderComboBox = (QComboBox)sender();
for (int i = 0; i < ui->tablWidget>rowCount(); i++) {
QComboBox uiComboBox = (QComboBox)ui->tableWidget->cellWidget(i, 0);
if (senderComboBox == uiCOmboBox){
//得到senderComboBox的行号
}
}
connect(combobox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(OnCurrentIndexChanged(int)));
connect(combobox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(OnCurrentIndexChanged(int)));
然后在函数中直接调用tablewidget的currentRow()即可。