QColorDialog and Qt::red



  • Simple code:

    @#include <QApplication>
    #include <QColorDialog>
    #include <QDebug>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    QColorDialog dlg;
    dlg.setWindowTitle("Change color");
    dlg.setCurrentColor(Qt::red);
    if (dlg.exec() == QDialog::Accepted)
    {
    QColor clr = dlg.selectedColor();
    qDebug() << clr;
    }

    return a.exec();
    }@

    Produces this

    !http://www.gamedev.ru/files/images/qcolordialog_bug.png!

    What am I doing wrong??



  • What version of Qt and what OS ?
    Just tried this on Qt5.4 /Ubuntu 14.04 and it behaved as expected.
    Dialog showed Red 254, Green 0, Blue 0.
    Debug output was QColor(ARGB 1, 1, 0, 0)



  • It is interesting because I also get same result as fsmoke. I have Qt 5.4 and opensuse 13.2 64 bit.



  • [quote author="mranger90" date="1420385805"]What version of Qt and what OS ?
    Just tried this on Qt5.4 /Ubuntu 14.04 and it behaved as expected.
    Dialog showed Red 254, Green 0, Blue 0.
    Debug output was QColor(ARGB 1, 1, 0, 0)
    [/quote]

    Windows 7, Qt 5.4.0.

    I got wrong color on Qt::green and Qt::yellow, But for example Qt::darkGreen works well

    PS
    Besides, why you got 254 but not 255?



  • Yes, I can reproduce this on windows with 5.4.
    It appears that a fully saturated color specification (255) is not accepted.
    In Linux, I noticed that Qt::red shows as 254, 0, 0 when it should be 255, 0, 0.
    On windows, you just get a wrong result. It happens for all the colors.



  • [quote author="mranger90" date="1420394347"]
    It appears that a fully saturated color specification (255) is not accepted.
    [/quote]

    It seems truth. Have anyone ideas how to fix it or avoid?



  • change the line of 11 with "dlg.setCurrentColor(QColor(254,0,0));"
    It worked for me.



  • [quote author="CKurdu" date="1420396472"]change the line of 11 with "dlg.setCurrentColor(QColor(254,0,0));"
    It worked for me.[/quote]

    no no no :))) it's ugly solution. Besides I found two problems

    1. QColorDialog::DontUseNativeDialog - this option does nothing, cos by default is no USE_NATIVE_COLOR_DIALOG defined. To use native color dialog you must rebuild qt
    2. setCurrentColor calls internal QColorDialogPrivate::setCurrentColor twice - first with normal color and second with aproximated color from color table

    I think need to add color to custom color table and then call setCurrentColor



  • It seems bug in QColorDialogPrivate::selectColor - variables row и column swaped




Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.