Results 1 to 7 of 7

Thread: color setting idiom

  1. #1
    Join Date
    Jun 2011
    Posts
    56
    Thanks
    7
    Qt products
    Qt4

    Default color setting idiom

    As I cannot set the alpha channel in any constructor of the QColor class, I am reduced to the following color-setting idiom:
    Qt Code:
    1. QColor color;
    2.  
    3. color.setRgba(QRgb(0x88FFFFFF));
    4. glossyGradient.setColorAt(0, color);
    5.  
    6. color.setRgba(QRgb(0x55FFFFFF));
    7. glossyGradient.setColorAt(.1f, color);
    8.  
    9. color.setRgba(QRgb(0x33FFFFFF));
    10. glossyGradient.setColorAt(.5f, color);
    11.  
    12. ...
    To copy to clipboard, switch view to plain text mode 

    This really isn't something to look at. Do there exist other possibilities?

  2. #2
    Join Date
    Dec 2010
    Location
    Russia
    Posts
    83
    Thanks
    1
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: color setting idiom

    Why not to use QColor::setAlpha ( int alpha ) or QColor::setAlphaF ( qreal alpha ) ?

  3. #3
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: color setting idiom

    One of the QColor constructors takes r,g,b,a values.

  4. #4
    Join Date
    Jun 2011
    Posts
    56
    Thanks
    7
    Qt products
    Qt4

    Default Re: color setting idiom

    Quote Originally Posted by AlexSudnik View Post
    Why not to use QColor::setAlpha ( int alpha ) or QColor::setAlphaF ( qreal alpha ) ?
    Because doing so would not be much different to what I am doing now.


    Added after 37 minutes:


    Quote Originally Posted by SixDegrees View Post
    One of the QColor constructors takes r,g,b,a values.
    Looks like I ought to file a Qt bug.
    Last edited by ugluk; 21st July 2011 at 10:16.

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: color setting idiom

    As I cannot set the alpha channel in any constructor of the QColor class
    As SixDegrees already stated, your assertion is false!
    See this constructor:
    http://doc.qt.nokia.com/latest/qcolor.html#QColor-2

    Looks like I ought to file a Qt bug.
    Why a bug?
    A bug is when something is not working as it should.
    Even if you were correct with your statement, and you could not set the alpha channel in a QColor ctror, it would still not be a bug, at worst, a missing feature.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: color setting idiom

    Why file a bug report? You claimed there wasn't a constructor that took an alpha channel argument; you were wrong, there is one, and it's clearly documented by Qt. How is this in any way a bug?

  7. #7
    Join Date
    Jun 2011
    Posts
    56
    Thanks
    7
    Qt products
    Qt4

    Default Re: color setting idiom

    Because the bugzilla accepts "bugs", which in reality are suggestions; Qt 5 is on the way, maybe something can change. Still, one might say, even though this is documented, that taking a QRgb argument and then ignoring the alpha channel in it is a bug (yes, I know it is not, but I wasted some time because of this behavior).

Similar Threads

  1. Saving color setting
    By waynew in forum Qt Programming
    Replies: 10
    Last Post: 13th January 2015, 13:15
  2. Setting Background Color
    By SixDegrees in forum Qt Programming
    Replies: 5
    Last Post: 16th February 2011, 18:33
  3. How can I get System setting color
    By dpatel in forum Qt Programming
    Replies: 2
    Last Post: 20th July 2010, 08:20
  4. QTreeWidgetItem setting color for the text
    By arjunasd in forum Qt Programming
    Replies: 1
    Last Post: 29th August 2007, 17:22
  5. setting text also changes color?
    By drhex in forum Qt Programming
    Replies: 5
    Last Post: 22nd November 2006, 16:36

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.