如何在QComboBox中显示具有给定索引号的项目?

问题描述 投票:0回答:2

我在

QComboBox
中添加了一些项目,现在我尝试在
QComboBox
上显示具有给定索引的项目。

例如:

在我的

QComboBox
中,我有三项;
firstItem
secondItem
thirdItem
,当我得到索引号二时,我想看到
secondItem
上显示的
QComboBox

qt qcombobox
2个回答
2
投票

您必须设置当前索引QComboBox::setCurrentIndex

ui->combo->setCurrentIndex(2);

0
投票

您可以使用

setCurrentIndex()
方法将 QComboBox 设置为根据索引显示您选择的任何项目。举个例子:

....     
artistView = new QComboBox; 
...
index = <some input>;
...
artistView->setCurrentIndex(index);///sets the index
© www.soinside.com 2019 - 2024. All rights reserved.