×
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 (Fix bad link to qt docs)
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot change of template (Template:CodeSnippet) - now using Template:ArticleMetaData)
Line 2: Line 2:
 
{{ReviewerApproved|timestamp=20090915}}
 
{{ReviewerApproved|timestamp=20090915}}
  
{{CodeSnippet
+
{{ArticleMetaData
 
|id=...
 
|id=...
 
|platform=Qt
 
|platform=Qt
Line 10: Line 10:
 
|creationdate=28 January 2009
 
|creationdate=28 January 2009
 
|keywords=QColorDialog,QColor
 
|keywords=QColorDialog,QColor
 +
 +
|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]]) -->
 +
|sdk=<!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
 +
|devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 +
|signing=<!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities=<!-- Capabilities required (e.g. Location, NetworkServices. -->)
 +
|author=[[User:James1980]]
 
}}
 
}}
  

Revision as of 11:53, 24 June 2011

{{{width}}}
15 Sep
2009
Article Metadata
Tested with
Devices(s): Emulator
Compatibility
Platform(s): Qt
Symbian
Platform Security
Capabilities: )
Article
Keywords: QColorDialog,QColor
Created: james1980 (28 Jan 2009)
Last edited: hamishwillee (24 Jun 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

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

×