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

Question about QColor and QColorDialog



  • Question about QColor and QColorDialog

    void MainWindow::on_pushButton_clicked()
    {
        QColor color = QColorDialog::getColor(Qt::black, this, "Choose Pixel Color");
    
        if(color.isValid())
        {
            qDebug() << color.convertTo(QColor::Spec QRgb);
        }
    }
    

    it outputs
    QColor(ARGB 1, 0, 1, 0)

    can i set the output to be RGB888 ? if yes how? :S i was in the docs for QColor but all i found was .toRgb but that did nothing



  • In QColor types, RGB = ARGB.
    If you want a QString like "#RRGGBB", you can use color.name().

    If you want an integer, the value of RGB24(888) equals the value of ARGB32 when alpha=0.
    So you can get it from:

    quint32 value = color.rgba() & 0xFFFFFF
    

    or

    color.setAlpha(0);
    quint32 value = color.rgba()
    

Log in to reply