//創建下拉框對象,並加入到表格對象中
QComboBox *comboBox = new QComboBox (); comboBox ->addItems(strListItems);//QStringList類型的元素 m_Table->setCellWidget(0,0,comboBox );//把下拉框加入到表格中
//如果表格的一行中既有QComboBox 類型的元素,也有QTableWidgetItem類型的元素,可以采用下面的方式來用: for(int col = 0; col < count; col++) { if( QComboBox *comboBox = dynamic_cast<QComboBox *>(table->cellWidget(0, col)) { comboBox->setCurrentIndex(index);//讓下拉框選到index對應的位置 } else { table->setItem(0,col,new QTableWidgetItem("value"); } }