| ID | ... | Creation date | 28 January 2009 |
| Platform | S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition | Tested on devices | Emulator |
| Category | Qt for Symbian | Subcategory |
| Keywords (APIs, classes, methods, functions): QColorDialog,QColor,QPalette,QLabel |
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.
#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);
}
}
#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
No related wiki articles found