Re: get a string's width in unit of pixel



Liu Neo-W4135C wrote:
i'm a newbie in GTK world and want to know how to get a string's width in unit of pixel( there should be a way, right).

First call:

PangoLayout *layout = gtk_widget_create_pango_layout(widget, "text");

on the widget that the string will be used for (different widget styles mean that you can't make a general function). Then call:

pango_layout_get_pixel_size(layout, &width, &height);

To get the width and height. Make sure ou free 'layout' when you're done with it by calling:

g_object_unref(G_OBJECT(layout));

--
Tim Evans
Applied Research Associates NZ
http://www.aranz.com/




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