×
Namespaces

Variants
Actions
(Difference between revisions)

Archived:How to select a color using QColorDialog

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Fix ArticleMetaData and RevieweApproval)
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
 
(6 intermediate revisions by one user not shown)
Line 1: Line 1:
 
{{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.}}
 
{{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.}}
[[Category:QWidget UI]][[Category:UI]]
+
[[Category:Qt C++ UI]][[Category:UI]][[Category:How To]][[Category:Code Snippet]]
 
+
{{Abstract|his code snippet demonstrates how to use the {{Qapiname|QColorDialog}} for colour selection.}}
 
+
{{ArticleMetaData <!-- v1.2 -->
{{ArticleMetaData <!-- v1.1 -->
+
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
Line 11: Line 10:
 
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
+
|signing= Self-Signed
|capabilities= <!-- Capabilities required (e.g. Location, NetworkServices. -->)
+
|capabilities= None
 
|keywords= QColorDialog,QColor
 
|keywords= QColorDialog,QColor
|id= ...
 
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|translated-by= <!-- [[User:XXXX]] -->
 
|translated-by= <!-- [[User:XXXX]] -->
Line 25: Line 23:
 
|creationdate= 20090128
 
|creationdate= 20090128
 
|author= [[User:James1980]]
 
|author= [[User:James1980]]
<!-- The following are not in current metadata -->
 
|subcategory= UI
 
|category= Qt
 
 
}}
 
}}
 
 
==Overview==
 
 
{{Abstract|visible=true|This code snippet demonstrates how to use the [http://doc.qt.nokia.com/stable/qcolordialog.html QColorDialog] for colour selection.}}
 
 
 
==Preconditions==
 
 
* Download and install the [[Qt SDK]]
 
 
  
 
== Source File ==
 
== Source File ==
  
<code cpp>
+
<code cpp-qt>
 
#include "dialogcolor.h"
 
#include "dialogcolor.h"
  
Line 77: Line 61:
 
== Header File ==
 
== Header File ==
  
<code cpp>
+
<code cpp-qt>
  
  
Line 112: Line 96:
 
[http://doc.qt.nokia.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]]
 
+
[[Category:How To]][[Category:Code Snippet]]
+

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.
266 page views in the last 30 days.