×
Namespaces

Variants
Actions
(Difference between revisions)

Archived:How to select a color using QColorDialog

From Nokia Developer Wiki
Jump to: navigation, search
kiran10182 (Talk | contribs)
hamishwillee (Talk | contribs)
m (Add Abstract. Point to correct Qt SDK)
Line 1: Line 1:
[[Category:Qt]]
+
[[Category:Qt]][[Category:UI]]
{{ReviewerApproved}}
+
{{ReviewerApproved|timestamp=20090915}}
__NOTOC__
+
 
__NOEDITSECTION__
+
 
{{CodeSnippet
 
{{CodeSnippet
 
|id=...
 
|id=...
Line 8: Line 7:
 
|devices= Emulator
 
|devices= Emulator
 
|category=Qt
 
|category=Qt
|subcategory=
+
|subcategory=UI
 
|creationdate=28 January 2009
 
|creationdate=28 January 2009
|keywords=QColorDialog,QColor,QPalette,QLabel
+
|keywords=QColorDialog,QColor
 
}}
 
}}
  
Line 16: Line 15:
 
==Overview==
 
==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]].
+
{{Abstract|visible=true|This code snippet demonstrates how to use the [http://doc.qt.nokia.com/stable/qcolordialog.html QColorDialog] for colour selection.}}
  
Qt provides a QColorDialog class for performing this task.
 
  
 
==Preconditions==
 
==Preconditions==
  
* Download and Install latest version [[Qt for Symbian - Installation packages]] which has links on how to install the latest version
+
* Download and install the [[Qt SDK]]
  
  
Line 104: Line 102:
 
[[Image:Co1.JPG]]
 
[[Image:Co1.JPG]]
  
[http://doc.qtsoftware.com/4.5/qcolordialog.html QColorDialog][[Category:How To]][[Category:Code Examples]]
+
[[Category:How To]][[Category:Code Examples]]

Revision as of 14:17, 24 April 2011

{{{width}}}
15 Sep
2009
Article Metadata
Tested with
Devices(s): Emulator
Compatibility
Platform(s): Qt
Symbian
Article
Keywords: QColorDialog,QColor
Created: (28 Jan 2009)
Last edited: hamishwillee (24 Apr 2011)


Contents

Overview

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


Preconditions

  • Download and install the Qt SDK


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

226 page views in the last 30 days.
×