Qt World Summit: Submit your Presentation

How to link signal of QColorDiaglog to a slot.

  • This is my code where i am opening a QColor diaglog.

    I want to reflect the change of color in realtime so want to link the colorChanged signal to a function.

    How can i link currentColorChanged(const QColor &color) of QDiaglog to slot ParamChangeCurrentKeyColor.

    void Sum_ChromaKey::ParamChangeKeyColor()
    	QColor color;
    	int r, g, b;
    	color = QColorDialog::getColor();  // link  currentColorChanged signal to  ParamChangeCurrentKeyColor
    	color.getRgb(&r, &g, &b);
    	_KeyColor.r = r;
    	_KeyColor.g = g;
    	_KeyColor.b = b;
    	// currentColorChanged(const QColor &color)
    void Sum_ChromaKey::ParamChangeCurrentKeyColor(const QColor &color)
    	_KeyColor.r = color.red;
    	_KeyColor.g = color.green;
    	_KeyColor.b = color.blue;

  • Lifetime Qt Champion


    you need to create your own instance in connect to that

    QColorDialog col;
    connect(&col, &QColorDialog::currentColorChanged,this, &Sum_ChromaKey::ParamChangeCurrentKeyColor);

  • @mrjj col.exec() would be a blocking function , can i do it with a non blocking function.

  • Lifetime Qt Champion

    Call open instead and then you need to use a pointer

            QColorDialog * col = new QColorDialog();
            col->setAttribute(Qt::WA_DeleteOnClose); // this deletes it when closed
            connect(col, &QColorDialog::currentColorChanged,this, &MainWindow::ParamChangeCurrentKeyColor);

  • @mrjj Thank you very much for your kind help.

  • Lifetime Qt Champion

    You are most welcome.
    Write good questions and we try the best to answer :)

Log in to reply