Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QColorDialog and Qt::red
Forum Updated to NodeBB v4.3 + New Features

QColorDialog and Qt::red

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 5.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fsmoke
    wrote on last edited by
    #1

    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??

    1 Reply Last reply
    0
    • mranger90M Offline
      mranger90M Offline
      mranger90
      wrote on last edited by
      #2

      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)

      1 Reply Last reply
      0
      • CKurduC Offline
        CKurduC Offline
        CKurdu
        wrote on last edited by
        #3

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

        You reap what you sow it

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fsmoke
          wrote on last edited by
          #4

          [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?

          1 Reply Last reply
          0
          • mranger90M Offline
            mranger90M Offline
            mranger90
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • F Offline
              F Offline
              fsmoke
              wrote on last edited by
              #6

              [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?

              1 Reply Last reply
              0
              • CKurduC Offline
                CKurduC Offline
                CKurdu
                wrote on last edited by
                #7

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

                You reap what you sow it

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  fsmoke
                  wrote on last edited by
                  #8

                  [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

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    fsmoke
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0
                    • F Offline
                      F Offline
                      fsmoke
                      wrote on last edited by
                      #10

                      see https://bugreports.qt-project.org/browse/QTBUG-42988

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved