Re: how to set link-color on Label



Le 27/08/2013 17:31, Ondrej Tuma a écrit :
Hi all,

i want to change link-color on some Label widgets, but only on some.

I can't find how i can do that. I will use in vala, but never mind, if
the example will be in python or C ;)

The GTK3 way would be either adding a style provider to you label
widget, roughly like this:

        var css = new Gtk.CssProvider();
        css.load_from_data("""
                GtkLabel {
                        -GtkWidget-link-color: yellow;
                        -GtkWidget-visited-link-color: green;
                }
        """, -1);

        /* ... */

        var label = new Gtk.Label("""<a href="http://gnome.org";>Link</a>""");
        label.use_markup = true;
        label.get_style_context().add_provider(css,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);


Or adding a style class to your label widget and add a custom provider
for the whole application:

        var label = new Gtk.Label("""<a href="http://gnome.org";>Link</a>""");
        label.use_markup = true;
        label.get_style_context().add_class(css, "mylabel");

After having added a global style provider (e.g. with
Gtk.StyleContext.add_provider_for_screen()).



You also always have the dirty-oh-god way that will only affect the base
color, not the :hover or :visited:

        var label = new Gtk.Label("""<span color="red"><a
href="http://gnome.org";>Link</a></span>""");

But some kittens would probably die if you do this.



Regards,
Colomban



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]