Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Archived:ComboBox with color palettes in Qt

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Qt Quick should be used for all UI development on mobile devices. The approach described in this article (based on QWidget) is deprecated.

Article Metadata
Tested with
Devices(s): Emulator,5800 XM
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
S60 5th Edition
S60 3rd Edition FP2
S60 3rd Edition FP1
Keywords: QPalette,QComboBox
Created: mind_freak (07 Aug 2009)
Last edited: hamishwillee (11 Oct 2012)


In this code the different color palette are set as QComboBox items. List of different colors is provided as strings from which the palette color is retrieved.

Name of classes used:

QPalette-Contains color groups for each widget state

QComboBox-widget is a combined button and popup list

Code Snippet

#include "widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
QStringList colorNms;
colorNms <<"darkGreen"<<"green"<<"gray"<<"red"<<"white"<<"blue"<<"cyan"<<"darkMagenta"<<"yellow"<<"darkRed"<<"black"<<"magenta";
Combcolor = new QComboBox(this);
QPalette pal = Combcolor->palette(); // holds the widget's palette.
pal.setColor(QPalette::Highlight, Qt::transparent); // construction of palette
Combcolor->setPalette(pal); //set the comboBox palette
int size = Combcolor->style()->pixelMetric(QStyle::PM_SmallIconSize);
QPixmap pixmap(size,size);
int con=0;
foreach (QString name, colorNms)
Combcolor->addItem("", QColor(con));//Adding ComboItems
Combcolor->setItemData(con, pixmap, Qt::DecorationRole);//Setting color palettes



This page was last modified on 11 October 2012, at 01:13.
148 page views in the last 30 days.