Namespaces
Variants
Actions

Archived:ComboBox with color palettes in Qt

Jump to: navigation, search
Archived.png
Archived: 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

Compatibility
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition

Article
Keywords: QPalette,QComboBox
Created: mind_freak (07 Aug 2009)
Last edited: hamishwillee (11 Oct 2012)

Overview

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);
Combcolor->setMinimumWidth(40);
Combcolor->setMaximumWidth(40);
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
pixmap.fill(QColor(name));
Combcolor->setItemData(con, pixmap, Qt::DecorationRole);//Setting color palettes
con=con+1;
}
}
 
Widget::~Widget()
{
}

Screenshot

Colorcombo.jpg

This page was last modified on 11 October 2012, at 04:13.
1226 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved