构造函数:
cpp
explicit QComboBox(QWidget *parent = nullptr);
添加内容
cpp
QComboBox *comboBox=new QComboBox(this);
comboBox->addItem("A1");
comboBox->addItem("A2");
comboBox->addItem("A3");
comboBox->addItem("A4");
comboBox->addItem("A5");
comboBox->addItem("A6");
//可以使用QStringList 一次写入多个数据
QStringList strList;
strList<<"A1"<<"A2"<<"A3"<<"A4"<<"A5"<<"A6";
comboBox->addItems(strList);
默认选项
cpp
comboBox->setCurrentIndex(0);
获取comboBox控件总索引数
cpp
int cou = comboBox->count();
qDebug()<< cou;
获取comboBox控件当前选中索引
cpp
int index = comboBox->currentIndex();//获得索引
QString StrIntN=QString::number(index);
QMessageBox::information(this, "comboBox", StrIntN, QMessageBox::Ok);
清除列表
cpp
comboBox->clear(); //清除列表