Qt Tutorials For Beginners – QColorDialog Example

Qt Tutorials For Beginners
Qt Tutorials For Beginners

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
  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;
  return 0;


Now run the code and see the output.

QColorDialog Output
QColorDialog Output


On terminal you will see the chosen color code

Color Choosen :  "#ffff00"


Partner Sites




Be the first to comment

Leave a Reply

Your email address will not be published.