×
Namespaces

Variants
Actions
(Difference between revisions)

Archived:How to select a color using QColorDialog

From Nokia Developer Wiki
Jump to: navigation, search
savaj (Talk | contribs)
(link updated)
mind_freak (Talk | contribs)
Line 47: Line 47:
 
dialogcolor::~dialogcolor()
 
dialogcolor::~dialogcolor()
 
{
 
{
 +
  if(button)
 +
  {
 +
    delete button;
 +
  }
 +
  if(colorlabel)
 +
  {
 +
    delete colorlabel;
 +
  }
 +
  if(layout)
 +
  {
 +
    delete layout;
 +
  }
  
 
}
 
}
Line 100: Line 112:
  
 
== Screenshot==
 
== Screenshot==
 
+
[http://doc.qtsoftware.com/4.5/qcolordialog.html QColorDialog]
  
 
[[Image:Colordialog.JPG]]
 
[[Image:Colordialog.JPG]]
Line 109: Line 121:
 
<br>
 
<br>
 
[[Image:Co1.JPG]]
 
[[Image:Co1.JPG]]
 +
 +
[http://doc.qtsoftware.com/4.5/qcolordialog.html QColorDialog]

Revision as of 17:11, 29 July 2009


Article Metadata
Tested with
Devices(s): Emulator
Compatibility
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
Symbian
Article
Keywords: QColorDialog,QColor,QPalette,QLabel
Created: (28 Jan 2009)
Last edited: mind_freak (29 Jul 2009)


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.

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");
connect(button, SIGNAL(clicked()), this, SLOT(setcolor()));
 
colorLabel =new QLabel;
layout = new QVBoxLayout;
layout->addWidget(button);
layout->addWidget(colorLabel);
setLayout(layout);
}
 
dialogcolor::~dialogcolor()
{
if(button)
{
delete button;
}
if(colorlabel)
{
delete colorlabel;
}
if(layout)
{
delete layout;
}
 
}
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>
#include <QString>
 
class dialogcolor : public QDialog
{
Q_OBJECT
 
public:
dialogcolor(QWidget *parent = 0);
~dialogcolor();
private slots:
void setcolor();
 
private:
QString str;
QPushButton *button;
QLabel *colorLabel;
QVBoxLayout *layout;
 
 
};
 
#endif // DIALOGCOLOR_H

Screenshot

QColorDialog

Colordialog.JPG


Co.JPG


Co1.JPG

QColorDialog

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.

×