i have the following code for QComboBox with WtreeView set as combo view
this->db->select("SELECT top 10 compa开发者_开发技巧ny, 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.
Try setting the model column to the one you want to change:
ui->comboBox->setModelColumn(2);
ui->comboBox->setCurrentIndex(index);
精彩评论