QT简单实现颜色下拉框:
void Widget::InitUI()
{
QComboBox* combo = new QComboBox(this);
combo->setMinimumWidth(300);
combo->setMinimumHeight(30);
int w = combo->width();
int h = combo->height();
QPixmap pix(w,h);
combo->setIconSize(QSize(w-60,h));
QMap<QString,QColor> map;
map.insert("红色",QColor(Qt::red));
map.insert("绿色",QColor(Qt::green));
map.insert("蓝色",QColor(Qt::blue));
foreach(auto key , map.keys()) {
QIcon icon;
pix.fill(map.value(key));
icon.addPixmap(pix);
combo->addItem(icon,key);
}
}