我有一个组合框我称之为:
QComboBox *comboBox_test ;
comboBox_test = new QComboBox(this);
comboBox_test ->setGeometry(QRect(10, 10, 50, 20));
comboBox_test ->insertItems(0, QStringList() << "A" << "B");
Run Code Online (Sandbox Code Playgroud)
我想要做的是将"B"设置为默认值.
我没有找到添加允许我这样做的行代码的方法.
根据您提供的示例,您有两种选择.在知道索引的情况下,可以直接使用setCurrentIndex(),或者首先使用findText检索索引
因此,最初你可以使用
comboBox_test->setCurrentIndex(1);
Run Code Online (Sandbox Code Playgroud)
稍后如果要在屏幕上重置为"B"
int index = comboBox_test->findText("B"); //use default exact match
if(index >= 0)
comboBox_test->setCurrentIndex(index);
Run Code Online (Sandbox Code Playgroud)