RE: different font in label



can some tell me, how I can change the font of my label ???
Okay okay, I know this one, I hope *G* okay do this.

GtkWidget *w = gtk_label_new("yiff");
GtkRcStyle *rcstyle = gtk_rcstyle_new();

rcstyle->font = gstrdup("put-font-spec-here");
gtk_widget_modify_style(w, rcstyle);

g_free(rcstyle->font);
rcstyle->font = NULL;
gtk_rcstyle_unref(rcstyle);

    (1) Does gtk_widget_modify_style(..) create it's own copy of style?
        [I have't remembered that]

    (2) Imho your way to do the task is wrong in principle, becase
         you change label's style too hard.
         Imho the better way is like that [but I can't say is it right or
         not :-|
         this code is modified tutorial's code.]:

        my_change_labels_font__but_it_may_be_buggy_and_it_is_untested(
/*Something here*/ )
        {
            GtkStyle*   style;
            GdkFont*   font;

            style = gtk_style_copy( gtk_widget_get_style (my_label) );
            gdk_font_unref (style->font); /* Font is double referenced by
my_label's style
                                                      * and by our's label
style. Remove our's ref.  */

            /* Setup font here, e.g. like above: font =
gstrdup("put-font-spec-here");
             * and add error checking here too, like: if ( font ) ...  */

            style->font = font;
            gdk_font_ref( style->font ); /* Add ref for our font. After this
string but before
                                                    * next one, our font and
that font ('that' is my_label's
                                                    * style's font) has only
one ref. */
            gtk_widget_set_style( my_label, style ); /* Remove old style and
copy new one. */
         }

---
 Dmitry Ponomaryov





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