Qt: QComboBox

Qt: QComboBox
QComboBox *comboBox = new QComboBox();
comboBox->addItem(QObject::tr("Red"), Qt::red);
...
QObject::connect(comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changePenColor()));

QPen pen;
QColor color = comboBox->itemData(comboBox->currentIndex(), Qt::UserRole).value<QColor>();
pen.setColor(color);

你可能感兴趣的:(Qt: QComboBox)