Qt Qcombbox显示图片样式

来源:互联网 发布:吴法天 知乎 编辑:程序博客网 时间:2024/05/18 00:31
foreach (const QString &colorName, colorNames) {const QColor color(colorName);//样式一// ui->comboBox->addItem(tr(colorName.toStdString().c_str()), color);// const QModelIndex idx = ui->comboBox->model()->index(index++, 0);// ui->comboBox->model()->setData(idx, color, Qt::BackgroundColorRole);//样式二QImage image(12,12,QImage::Format_RGB32);QPainter painter(&image);painter.fillRect(0,0,12,12,color); QIcon icon; icon.addPixmap(QPixmap::fromImage(image)); ui->comboBox->addItem(icon, tr(colorName.toStdString().c_str()));}

原创粉丝点击