C++ (Qt)#include <QApplication>#include <QComboBox>#include <QStandardItemModel> int main( int argc, char** argv ){ QApplication app( argc, argv ); QComboBox cb; char *colors[] = { "brown", "orange", "yellow", "green", "lightblue", "blue", "purple" }; QStandardItemModel* m = qobject_cast< QStandardItemModel* >( cb.model() ); m->setRowCount( 7 ); for( int i = 0; i < 7; i++ ) { QModelIndex mi = m->index( i, 0 ); m->setData( mi, colors[i], Qt::DisplayRole ); m->setData( mi, QColor( colors[i] ), Qt::TextColorRole ); m->setData( mi, QColor( colors[i] ), Qt::DecorationRole ); } cb.show(); return app.exec();}
QStandardItemModel* m = qobject_cast< QStandardItemModel* >( this->model() ); for( int i = 0; i < 32; i++ ) { QModelIndex mi = m->index( i, 0 ); m->setData( mi, QColor(255,0,255), Qt::ForegroundRole ); }