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. get the numeric RGB color values ( QColor)

get the numeric RGB color values ( QColor)

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 3.0k Views
  • 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.
  • C Offline
    C Offline
    Craiginator
    wrote on 24 Jan 2020, 22:15 last edited by
    #1

    Screenshot from 2020-01-24 16-59-55.png

    Using QColor selection, I would like to know how to get and store the individual R, G, B values as 0-255.
    In my example below, I'm just focusing on trying to get one value to work so I understand the concept, but the output is not as I'd expect.

    • When I pick pure red from the color selector, my debug code is showing the output of MyRed as: Color Choosen : "ÿ"

    • What I want and thought would display based on the help file is: Color Choosen : "255"

    • Then, what I ultimately need to get to is something like pure red yields MyRed = 255 , MyGreen = 0, MyBlue = 0

    void MainWindow::on_pushButton_clicked()
    {
      QString MyRed;
    
        QColor color = QColorDialog::getColor(Qt::yellow, this ).rgb();
        if( color.isValid() )
        {
    
          //qDebug() << "Color Choosen : " << color.name();
          MyRed = color.red();
          qDebug() << "Color Choosen : " << MyRed;
    
    }
    };
    
    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 24 Jan 2020, 22:18 last edited by
      #2

      @Craiginator said in get the numeric RGB color values ( QColor):

      MyRed = color.red();

      You're assigning an integer to a QString - what do you expect??
      You're looking either for QString::number() or simply

      qDebug() << "Color Choosen : " << color.red();

      or even

      qDebug() << "Color Choosen : " << color.name(QColor::HexArgb);

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • C Offline
        C Offline
        Craiginator
        wrote on 24 Jan 2020, 22:30 last edited by
        #3

        Holy Cow , that was silly. I waisted more time than I'd like to say and all over 1 mistake I kept overlooking.
        Thanks!

        1 Reply Last reply
        1
        • K Offline
          K Offline
          Kent-Dorfman
          wrote on 26 Jan 2020, 04:52 last edited by
          #4

          @Christian-Ehrlicher said in get the numeric RGB color values ( QColor):

          You're assigning an integer to a QString - what do you expect??
          You're looking either for QString::number() or simply

          and one of the huge dangers of overloaded constructors run amuck.

          1 Reply Last reply
          1

          3/4

          24 Jan 2020, 22:30

          • Login

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