我在
QComboBox
中添加了一些项目,现在我尝试在 QComboBox
上显示具有给定索引的项目。
例如:
在我的
QComboBox
中,我有三项; firstItem
,secondItem
,thirdItem
,当我得到索引号二时,我想看到secondItem
上显示的QComboBox
。
您必须设置当前索引QComboBox::setCurrentIndex。
ui->combo->setCurrentIndex(2);
您可以使用
setCurrentIndex()
方法将 QComboBox 设置为根据索引显示您选择的任何项目。举个例子:
....
artistView = new QComboBox;
...
index = <some input>;
...
artistView->setCurrentIndex(index);///sets the index