Results 1 to 6 of 6

Thread: RGB QColor(QRgb)

  1. #1
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default RGB QColor(QRgb)

    I want to create a QColor,I find that QColorcan be created by
    Qt Code:
    1. QColor(int r,int g,int b,int a=255)
    To copy to clipboard, switch view to plain text mode 
    or by
    Qt Code:
    1. QColor(QRgb color)
    To copy to clipboard, switch view to plain text mode 
    ,Now I have two questions:
    1.if the value of r,g,b is between 0 and 1,how to convert to int? because
    Qt Code:
    1. QColor(int r,int g,int b,int a=255)
    To copy to clipboard, switch view to plain text mode 
    need int parameter?
    2.If I use
    Qt Code:
    1. QColor(QRgb color)
    To copy to clipboard, switch view to plain text mode 
    to create a color,how to convert (0,1) to tpye QRgb?
    Thk u.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: RGB QColor(QRgb)

    there is QRgb qRgba ( int r, int g, int b, int a ), use it.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: RGB QColor(QRgb)

    QRgb qRgba ( int r, int g, int b, int a ),which needs int parameter,but I have the value of r,g,b is between 0 and 1? How to convert them to int value?
    thank u.

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: RGB QColor(QRgb)

    You have to manually map the values from.
    0..........1

    On

    0..........255

    Then pass the mapped value in qRgba(); I am not good in Mathematics otherwise could have provide you the actual solution.

  5. #5
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: RGB QColor(QRgb)

    If you just want to create a QColor from rgb values between 0 and 1, you can also use QColor::setRgbF(). No need to think about
    Qt Code:
    1. (quint8)(value*255)
    To copy to clipboard, switch view to plain text mode 
    and polluting your code with it.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  6. #6
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: RGB QColor(QRgb)

    thk u.i wil try.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.