[Gambas-user] Widget colours: how to change them for all widget states?

RICHARD WALKER richard.j.walker at ...247...
Fri Jun 29 02:50:26 CEST 2012


This isn't something I have ever worried about before, but just
recently I have been playing with form and control colours and I have
hit a problem.

I can change the colour of a form or a button or other displayed item.
I can change the foreground text colour too so I get decent contrast
if I am using a darker background colour. What I cannot do is change
the various state-dependent colours of a control which can result in
the button label text (for instance) disappearing due to lack of
contrast when a button is hovered over with the mouse.

I tried to solve this issue by writing "enter" and "leave" event
handlers. Their only purpose is to change the control foreground
colour to an appropriate contrasting colour when the mouse enters and
restore the original colour when it leaves. Of course you have to be
moderate in your use of mouse speed on leaving the control or you
could get the mouse off the form completely without actually
triggering the "leave" event. That looks messy.

Another approach I have tried is to leave the control caption blank
and put the appropriate label in its tooltip instead. That always has
good contrast, but it isn't a perfect solution either.

A third solution I have tried is to replace the caption text with a
picture; either a picture of text or an icon. This only works well if
you also provide a colour background for the text/icon which supplies
the right contrast. The background really ought to be the full size of
the button, or the label background, to prevent ugly bright flashes as
the pale highlighting colour will show through anywhere you leave
uncovered, but in general this can be quite a successful workaround
you can use on a darker coloured form.

None of these strategies will be useful if there are controls on the
form which may be "disabled" by your program. Just as there is no
"entered colour" property, neither is there a "disabled colour"
property that I could find. Although I have not yet tested the theory,
I imagine I could dodge the problem if instead of disabling a
component, I just bring a duplicate component to the top in the same
location and "hide" the disabled version. The duplicate might have to
be a picture of a control to prevent its colour from changing and
making it look active.

If anyone knows a better way, or if there is some trick I have
overlooked I would be glad to hear of it.

Richard




More information about the User mailing list