Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

    Hi

    you need to create your own instance in connect to that

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


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


  • Lifetime Qt Champion

    @summit
    Hi
    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);
            col->open();
    


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


  • Lifetime Qt Champion

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


Log in to reply