How to set selected item in QComboBox with QtreeVi

2019-05-24 13:40发布

i have the following code for QComboBox with WtreeView set as combo view

this->db->select("SELECT top 10 company, address, phone, id FROM data");
QTreeView *ptv = new QTreeView(this);
ptv->setModel(this->db->model);
ptv->setColumnHidden(3, true);
ui->comboBox->setModel(this->db->model);
ui->comboBox->setView(ptv);
connect(ui->comboBox, SIGNAL(activated(int)), this, SLOT(getComboIndex(int)));

How can i set selected item or index for column 2 for example. I can set the first column with

ui->comboBox->setCurrentIndex(index);

but this is not working for other column only for the first.

1条回答
SAY GOODBYE
2楼-- · 2019-05-24 14:02

Try setting the model column to the one you want to change:

ui->comboBox->setModelColumn(2);
ui->comboBox->setCurrentIndex(index);
查看更多
登录 后发表回答