Re: why gtk_label_set_attributes not change anything?



"chen.shengqi" <chen shengqi connet com tw> writes:

Dear sirs:
    I'm using gnome 2.0 on solaris, the follow code did not change any thing, the label is always black 
font on screen. What's the correct method to change property of GtkLabel? thanks.

 PangoAttribute *pa;
 PangoAttrList *tmpattr,*oldattr=NULL;
 guint16 r,g,b;
 int rgb;
 GtkLabel *DestLabel=NULL;
 tmpattr = pango_attr_list_new();
 rgb = COLORS[2];
   r=((rgb>>16)&0x000000FF)*255;

Note that you should use 257 here, not 255.

   g=((rgb>>8)&0x000000FF)*255;
   b=((rgb)&0x000000FF)*255;
 pa = pango_attr_foreground_new(r,g,b);

When you create an attribute, you need to set attr->start_index
and attr->end_index, or it won't apply to any characters.

 pango_attr_list_insert(tmpattr,pa);
   rgb = COLORS[9];
   r=((rgb>>16)&0x000000FF)*255;
   g=((rgb>>8)&0x000000FF)*255;
   b=((rgb)&0x000000FF)*255;
   pa = pango_attr_background_new(r,g,b);
   pango_attr_list_insert(tmpattr,pa);
 
 DestLabel = (GtkLabel *)lookup_widget(drawingcanvas->parent,
                                        "sware_work_name");
 if (DestLabel==NULL) return;
 gtk_label_set_label(DestLabel,"hello");
 if (DestLabel)
 {
  oldattr = gtk_label_get_attributes(DestLabel);
  if (oldattr) pango_attr_list_unref(oldattr);
  else debug(1)("no oldattr \n");
  gtk_label_set_attributes(DestLabel,tmpattr);
 }

You could make things easier by yourself by just doing:

 gtk_label_set_attributes (DestLabel, tmpattr);
 pango_attr_list_unref (tmpattr)

Then you can just forget about attribute list and it
will be freed with the label or when you set a new
attribute list.

You might want to consider using gtk_widget_modify_fg()
gtk_widget_modify_bg() instead ... they are easier to use.
But note that the GtkLabel widget doesn't have a background
so you'll have to put it inside a different widget (like
a GtkEventBox) and set the backgrourd on that.

Regards,
                                        Owen



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