Qt: QComboBox: QIcon Item

Qt: QComboBox: QIcon Item

#include <QtCore/QTextCodec>

#include <QtGui/QApplication>

#include <QtGui/QComboBox>

#include <QtGui/QPixmap>

#include <QtGui/QPainter>


int main(int argc, char *argv[]) {

    QApplication app(argc, argv);


    QPixmap pixmap(16, 16);

    QPainter painter(&pixmap);

    QComboBox *comboBox = new QComboBox();


    painter.fillRect(0, 0, 16, 16, Qt::red);

    comboBox->addItem(QIcon(pixmap), QObject::tr("Red"), Qt::red);

    painter.fillRect(0, 0, 16, 16, Qt::black);

    comboBox->addItem(QIcon(pixmap), QObject::tr("Black"), Qt::black);

    painter.fillRect(0, 0, 16, 16, Qt::white);

    comboBox->addItem(QIcon(pixmap), QObject::tr("White"), Qt::white);

    painter.fillRect(0, 0, 16, 16, Qt::green);

    comboBox->addItem(QIcon(pixmap), QObject::tr("Green"), Qt::green);


    comboBox->setVisible(true);


    return app.exec();

}

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