Re: How to change color of Gtk::RadioButton's label?




Paul Davis wrote:

>there are ways of drawing a Pango layout that would pay attention to the
>atttributes you are trying to set. however, these are not the ways that
>are used by a Gtk::Label in its expose event handling.
>
>  
>
My test case bears you out Paul, but I have to wonder if it is for the
reasons you state.  The following code compiles and runs,

<code>

#include <gtkmm.h>

int main(int argc, char**argv)
{
    Gtk::Main kit(argc, argv);
    Glib::RefPtr<Pango::Layout> layout;
    PangoAttrColor pa;
    PangoColor pc;
    pc.red = 65535;
    pc.green = 0;
    pc.blue = 0;
    pa.attr = *pango_attr_background_new(0xffff,0x0,0x0);
    pa.color = pc;
   
    Pango::AttrColor attcolor(&pa);
   
    Gtk::Window win;
    win.set_default_size(100,75);
    Gtk::CheckButton check;
    Gtk::Label* l=Gtk::manage(new Gtk::Label);
    l->set_text("blue text");
    layout = l->get_layout();
    if(layout)
    {
        Pango::AttrList attlist(layout->get_attributes());
        attlist.change(attcolor);
        layout->set_attributes(attlist);
    }
   
    l->modify_fg(Gtk::STATE_NORMAL , Gdk::Color("blue"));
    check.add(*l);
    win.add(check);
    win.show_all_children();
    kit.run(win);
   
    return 0;
}

</code>

but it gets the following assertion at the commandline:

(testbg:25505): Pango-CRITICAL **: pango_attr_list_change: assertion
`list != NULL' failed

Nevertheless, it does display a window with a checkbutton with blue text.

So, I have to wonder *why* I'm getting a bad pango_attr_list from the
Pango::Layout returned from the Gtk::Label::get_layout method.

Bob



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