×
Namespaces

Variants
Actions
(Difference between revisions)

Archived:How to select a color using QColorDialog

From Nokia Developer Wiki
Jump to: navigation, search
jimgilmour1 (Talk | contribs)
m (new release Qt 4.6.0 for Symbian "Colossus" beta-release download page)
kiran10182 (Talk | contribs)
m (Qt for Symbian -> Qt)
Line 1: Line 1:
[[Category:Qt]][[Category:Qt for Symbian]][[Category:How To]][[Category:Code Examples]]
+
[[Category:Qt]]
 
{{ReviewerApproved}}
 
{{ReviewerApproved}}
 
__NOTOC__
 
__NOTOC__
Line 5: Line 5:
 
{{CodeSnippet
 
{{CodeSnippet
 
|id=...
 
|id=...
|platform=S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
+
|platform=Qt
 
|devices= Emulator
 
|devices= Emulator
|category=Qt for Symbian
+
|category=Qt
 
|subcategory=
 
|subcategory=
 
|creationdate=28 January 2009
 
|creationdate=28 January 2009
Line 16: Line 16:
 
==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 for S60]].
+
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]].
  
 
Qt provides a QColorDialog class for performing this task.
 
Qt provides a QColorDialog class for performing this task.
Line 104: Line 104:
 
[[Image:Co1.JPG]]
 
[[Image:Co1.JPG]]
  
[http://doc.qtsoftware.com/4.5/qcolordialog.html QColorDialog]
+
[http://doc.qtsoftware.com/4.5/qcolordialog.html QColorDialog][[Category:How To]][[Category:Code Examples]]

Revision as of 14:51, 1 April 2011

{{{width}}}


Article Metadata
Tested with
Devices(s): Emulator
Compatibility
Platform(s): Qt
Symbian
Article
Keywords: QColorDialog,QColor,QPalette,QLabel
Created: (28 Jan 2009)
Last edited: kiran10182 (01 Apr 2011)


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.

Qt provides a QColorDialog class for performing this task.

Preconditions


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

QColorDialog

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

×