GTKD - overrideBackgroundColor of Button doesn't work

Gerald via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jun 16 06:12:12 PDT 2016


On Thursday, 16 June 2016 at 07:58:56 UTC, TheDGuy wrote:
> On Wednesday, 15 June 2016 at 22:34:05 UTC, Gerald wrote:
>> snip...
>>
>>> The text color is green but the button background color is 
>>> still default-gray!
>>
>> I don't see an obvious issue with your code, I usually use CSS 
>> classes personally and I know that works fine because I use 
>> this technique all over terminix. I would suggest using the 
>> GTK Inspector to debug the CSS issue, it's an awesome tool for 
>> figuring out GTK CSS issues as it let's you change CSS on the 
>> fly, see what CSS is being applied to an object, etc. You can 
>> see how to use it at the link below:
>>
>> https://wiki.gnome.org/Projects/GTK%2B/Inspector
>>
>
> Do you know if this works on windows?

No idea, I don't use Windows.

>
>> Personally I just add and remove classes as needed:
>>
>> getStyleContext().addClass()
>> getStyleContext().removeClass()
>
> So you basically have to create 2 classes? And what would you 
> do if you would have to change the color randomly (for a simon 
> says game)? I still think it is a bad idea to claim the way 
> with function calls as deprecated but introducing a new system 
> which is not as flexible (but maybe more powerfull).
> C# with Visual Studio does it, PyQT does it: Function calls.

It can be done fine with on the fly changes, i.e. random colors, 
it's somewhat more work then just calling a simple function call 
but CSS gives you a lot more power as well. I do this in Terminix 
where for certain themes I want to set the scrollbar background 
to be the same color as the terminal background.

Essentially, add a class to the widget and then construct the CSS 
for the class with your random background color as a string. 
Create a CSSProvider and use loadFromData, same as captaindet's 
example, to load the CSS in the string. Finally, use the widget's 
style context to add the CSS provider which you just constructed. 
If you want to change the color, remove that provider and add a 
new one.


More information about the Digitalmars-d-learn mailing list