现在的位置: 首页 > 综合 > 正文

Qt Qcombbox显示图片样式

2013年10月04日 ⁄ 综合 ⁄ 共 493字 ⁄ 字号 评论关闭
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()));
	}

【上篇】
【下篇】

抱歉!评论已关闭.