QT Color Dialog Demo
In this lesson we will learn how to use QColorDialog in qt.
The QColorDialog class provides a dialog widget for specifying colors.
File->New File or Project…
Applications->Qt Gui Application->Choose…
We keep the class as MainWindow as given by default.
Now write the code shown below in main.cpp
#include <QApplication>
#include <QDebug>
#include <QColorDialog>
class QColorDialogTester : public QWidget
{
public:
void onColor()
{
QColor color = QColorDialog::getColor(Qt::yellow, this );
if( color.isValid() )
{
qDebug() << "Color Choosen : " << color.name();
}
}
};
int main( int argc, char **argv )
{
QApplication app( argc, argv );
QColorDialogTester color_test;
color_test.onColor();
return 0;
}
Now run the code and see the output.

On terminal you will see the chosen color code
Color Choosen : "#ffff00"
Leave a Reply