In Windows when a control is disabled it looks grayed out. What type of algorithm could be used to achieve this kind of effect?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t know how Windows does it, but if you’re looking for an example of how it is often done, check out Qt’s QPalette class (and in particular the screenshot in the QPalette::ColorRole section).
What Qt does is choose colors to draw widget parts with based on ColorRoles, so e.g. there is a “Button” ColorRole which represents the color of the interior of a button. When the button wants to draw itself, it asks its QPalette object what color it should use for the Button ColorRole, and then it draws its interior using that color. The button holds one QPalette object for use with its normal-look and a second QPalette object for use with its disabled-look… and the colors specified by the disabled-look QPalette will typically tend more toward gray as opposed to the normal QPalette’s black/white (although it is up to the designer of the QStyle to decide what they should be).
(of course the quick-and-dirty way to make a control look grayed-out would be to just average the red, green, and blue values of each color in the control with the red, green, and blue values of a medium-gray… but that trick won’t provide enough control to get you the exact look you want in all situations)