kode
kode

Reputation: 1078

How to set selected item in QComboBox with QtreeView

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.

Upvotes: 2

Views: 5064

Answers (1)

ismail
ismail

Reputation: 47572

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

ui->comboBox->setModelColumn(2);
ui->comboBox->setCurrentIndex(index);

Upvotes: 3

Related Questions