×
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 (Add Abstract. Point to correct Qt SDK)
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
 
(9 intermediate revisions by one user not shown)
Line 1: Line 1:
[[Category:Qt]][[Category:UI]]
+
{{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.}}
{{ReviewerApproved|timestamp=20090915}}
+
[[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.}}
{{CodeSnippet
+
{{ArticleMetaData <!-- v1.2 -->
|id=...
+
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
|platform=Qt
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|devices= Emulator
 
|devices= Emulator
|category=Qt
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|subcategory=UI
+
|platform= Qt
|creationdate=28 January 2009
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|keywords=QColorDialog,QColor
+
|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==
 
 
{{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 59: Line 61:
 
== Header File ==
 
== Header File ==
  
<code cpp>
+
<code cpp-qt>
  
  
Line 92: 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]]
 
+
[[Category:How To]][[Category:Code Examples]]
+

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

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×