QComboBox下拉框 + 顏色相關
阿新 • • 發佈:2019-01-26
1.通過QPalette設定顏
//通過QPalette設定顏色--QPalette::ColorRole
QPalette p = widget->palette();
p.setColor(QPalette::Base,color);
widget->setPalette(p);
2.QComboBox下拉框
//QComboBox下拉框
QComboBox *comboBox =new QComboBox;
comboBox->addItem(tr("text1"));
comboBox->addItem(tr("text2"));
//獲取當前下拉框所在的位置
int index = comboBox->currentIndex();
3.新增所有顏色下拉框
//新增所有顏色下拉框
QStringList colorList = QColor::colorNames();
QString color;
foreach(color,colorList)
{
QPixmap pix(QSize(70,20));
pix.fill(QColor(color));
comboBox->addItem(QIcon(pix),NULL);
comboBox->setIconSize(QSize(70,20));
comboBox->setSizeAdjustPolicy (QComboBox::AdjustToContents);
}