开发者

How to set selected item in QComboBox with QtreeView

开发者 https://www.devze.com 2023-02-01 05:05 出处:网络
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\");

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消