QCombobox of Checkboxes

那年仲夏 提交于 2019-12-12 01:24:55

问题


I have a problem and I hope that you can help me. I want to create a Combobox of Checkboxes on Qt Creator. This is my code

mod = new QStandardItemModel(1,0);
QStandardItem *item;
item = new QStandardItem("First");
item->setCheckable(true);
mod->setItem(0,item);
item = new QStandardItem("Second");
item->setCheckable(true);
mod->setItem(1,item);
ui->comboBox->setModel(mod);

I built this code but in combobox are no checkboxees. Someone on the web told me that I have to use the event. Can you help me?


回答1:


you only have to set an initial checkState additonally

item->setCheckState(Qt::CheckState state);

e.g.

item->setCheckState(0);


来源:https://stackoverflow.com/questions/29589274/qcombobox-of-checkboxes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!