×
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 - Addition to article of: Category:MeeGo Category:Symbian. (Add platform categories))
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Fix ArticleMetaData and other issues)
Line 1: Line 1:
[[Category:QWidget UI]][[Category:UI]][[Category:How To]][[Category:Code Snippet]]
+
[[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.}}
 
{{Abstract|his code snippet demonstrates how to use the {{Qapiname|QColorDialog}} for colour selection.}}
 
{{Archived|timestamp=20120209041840|user=[[User:Hamishwillee|<br />----]]|[[: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|<br />----]]|[[: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.}}
{{ArticleMetaData <!-- v1.1 -->
+
{{ArticleMetaData <!-- v1.2 -->
 
|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 96: 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]][[Category:MeeGo]] [[Category:Symbian]]
+
[[File:Co1.JPG]][[Category:MeeGo]] [[Category:Symbian]]

Revision as of 13:28, 2 March 2012

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

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
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 (02 Mar 2012)

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);
}
}

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

Screenshot

QColorDialog

Colordialog.JPG


Co.JPG


Co1.JPG

273 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.

×