×
Namespaces

Variants
Actions
(Difference between revisions)

Archived:How to select a color using QColorDialog

From Nokia Developer Wiki
Jump to: navigation, search
axeljaeger (Talk | contribs)
(Remove unneeded member str.)
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
 
(19 intermediate revisions by 7 users not shown)
Line 1: Line 1:
[[Category:Qt]][[Category:Qt for S60]][[Category:How To]][[Category:Code Examples]]
+
{{Archived|timestamp=20120209041840|user=[[User:Hamishwillee|&lt;br /&gt;----]]|[[:Category:Qt Quick|Qt Quick]] should be used for all UI development on mobile devices. The approach described in this article (based on {{Qapiname|QWidget}}) is deprecated.}}
__NOTOC__
+
[[Category:Qt C++ UI]][[Category:UI]][[Category:How To]][[Category:Code Snippet]]
__NOEDITSECTION__
+
{{Abstract|his code snippet demonstrates how to use the {{Qapiname|QColorDialog}} for colour selection.}}
{{CodeSnippet
+
{{ArticleMetaData <!-- v1.2 -->
|id=...
+
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
|platform=S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|devices= Emulator
 
|devices= Emulator
|category=Qt for S60
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|subcategory=
+
|platform= Qt
|creationdate=28 January 2009
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|keywords=QColorDialog,QColor,QPalette,QLabel
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= Self-Signed
 +
|capabilities= None
 +
|keywords= QColorDialog,QColor
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20090128
 +
|author= [[User:James1980]]
 
}}
 
}}
 
 
==Overview==
 
 
This code snippet demonstrates how to allow user to select a color of his choice and use it as either a background or foreground color in [[Qt for S60]].
 
 
Qt provides a QColorDialog class for performing this task.
 
 
==Preconditions==
 
 
* [http://pepper.troll.no/s60prereleases/ Download the latest Qt for S60 distribution from Qt Software].
 
* Install Qt for S60:[[Installing Qt on S60]]
 
* Check this link for installation guide: [http://pepper.troll.no/s60prereleases/doc/install-s60.html How to install the package].
 
* Go through this article: [[Getting started with Qt for S60]]
 
 
  
 
== Source File ==
 
== Source File ==
  
<code cpp>
+
<code cpp-qt>
 
#include "dialogcolor.h"
 
#include "dialogcolor.h"
  
Line 63: Line 61:
 
== Header File ==
 
== Header File ==
  
<code cpp>
+
<code cpp-qt>
  
  
Line 96: Line 94:
  
 
== Screenshot==
 
== Screenshot==
[http://doc.qtsoftware.com/4.5/qcolordialog.html QColorDialog]
+
[http://doc.qt.nokia.com/4.5/qcolordialog.html QColorDialog]
  
[[Image:Colordialog.JPG]]
+
[[File:Colordialog.JPG]]
  
 
<br>
 
<br>
[[Image:Co.JPG]]
+
[[File:Co.JPG]]
  
 
<br>
 
<br>
[[Image:Co1.JPG]]
+
[[File:Co1.JPG]][[Category:MeeGo Harmattan]] [[Category:Symbian]]
 
+
[http://doc.qtsoftware.com/4.5/qcolordialog.html QColorDialog]
+

Latest revision as of 04:14, 11 October 2012

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.

his code snippet demonstrates how to use the QColorDialog for colour selection.

Article Metadata
Tested with
Devices(s): Emulator
Compatibility
Platform(s): Qt
Symbian
Platform Security
Signing Required: Self-Signed
Capabilities: None
Article
Keywords: QColorDialog,QColor
Created: james1980 (28 Jan 2009)
Last edited: hamishwillee (11 Oct 2012)

[edit] Source File

#include "dialogcolor.h"
 
dialogcolor::dialogcolor(QWidget *parent)
: QDialog(parent)
{
button = new QPushButton("Select Color", this);
connect(button, SIGNAL(clicked()), this, SLOT(setcolor()));
 
colorLabel =new QLabel(this);
layout = new QVBoxLayout(this);
layout->addWidget(button);
layout->addWidget(colorLabel);
setLayout(layout);
}
 
dialogcolor::~dialogcolor()
{
// No need to delete any object that got a parent that is properly deleted.
}
void dialogcolor::setcolor()
{
QColor color = QColorDialog::getColor(Qt::green, this);
if (color.isValid())
{
colorLabel->setText(color.name());
colorLabel->setPalette(QPalette(color));
colorLabel->setAutoFillBackground(true);
}
}

[edit] Header File

#ifndef DIALOGCOLOR_H
#define DIALOGCOLOR_H
 
#include <QtGui/QDialog>
#include "ui_dialogcolor.h"
#include <QPushButton>
#include <QColorDialog>
#include <QLabel>
#include <QVBoxLayout>
 
class dialogcolor : public QDialog
{
Q_OBJECT
 
public:
dialogcolor(QWidget *parent = 0);
~dialogcolor();
private slots:
void setcolor();
 
private:
QPushButton *button;
QLabel *colorLabel;
QVBoxLayout *layout;
};
 
#endif // DIALOGCOLOR_H

[edit] Screenshot

QColorDialog

Colordialog.JPG


Co.JPG


Co1.JPG

This page was last modified on 11 October 2012, at 04:14.
189 page views in the last 30 days.
×