1 <refentry id="gtk-question-index" revision="1 Jan 2002">
3 <refentrytitle>Common Questions</refentrytitle>
4 <manvolnum>3</manvolnum>
5 <refmiscinfo>Common Questions</refmiscinfo>
9 <refname>Common Questions</refname>
11 Find answers to common questions in the GTK+ manual
16 <title>Questions and Answers</title>
19 This is an "index" of the reference manual organized by common "How do
20 I..." questions. If you aren't sure which documentation to read for
21 the question you have, this list is a good place to start.
26 <qandadiv><title>General</title>
30 Where can I get help with GTK+, submit a bug report, or make a feature
37 See the <link linkend="gtk-resources">documentation on this topic</link>.
46 <question><para>How do I port from one GTK+
47 version to another?</para></question>
52 See the <link linkend="gtk-changes-2-0">list of incompatible changes
53 from 1.2 to 2.0</link>. Also, the <ulink
54 url="http://developer.gnome.org/dotplan/porting/">GNOME 2.0 porting
55 guide</ulink> on <ulink
56 url="http://developer.gnome.org">http://developer.gnome.org</ulink>
57 has some more detailed discussion of porting from 1.2 to 2.0.
58 You may also find useful information in the documentation for
59 specific widgets and functions.
63 If you have a question not covered in the manual, feel free to
64 ask on the mailing lists and please <ulink
65 url="http://bugzilla.gnome.org">file a bug report</ulink> against the
76 How does memory management work in GTK+? Should I free data returned
83 See the documentation for <link linkend="GObject">GObject</link> and
84 <link linkend="GtkObject">GtkObject</link>. For <link
85 linkend="GObject">GObject</link> note specifically <link
86 linkend="g-object-ref">g_object_ref()</link> and <link
87 linkend="g-object-unref">g_object_unref()</link>. <link
88 linkend="GtkObject">GtkObject</link> is a subclass of <link
89 linkend="GObject">GObject</link> so the same points apply, except that
90 it has a "floating" state (explained in its documentation).
94 For strings returned from functions, they will be declared "const"
95 (using <link linkend="G-CONST-RETURN-CAPS">G_CONST_RETURN</link>) if they
96 should not be freed. Non-const strings should be freed with <link
97 linkend="g-free">g_free()</link>. Arrays follow the same rule. (If
98 you find an exception to the rules, please report a bug to <ulink
99 url="http://bugzilla.gnome.org">http://bugzilla.gnome.org</ulink>.)
109 How do I use GTK+ with threads?
115 This is covered in the
116 <link linkend="gdk-Threads">GDK threads documentation</link>.
117 See also the <link linkend="glib-Threads">GThread</link> documentation for portable
118 threading primitives.
128 How do I load an image or animation from a file?
134 To load an image file straight into a display widget, use <link
135 linkend="gtk-image-new-from-file">gtk_image_new_from_file()</link>
136 <footnote><para> If the file load fails, <link
137 linkend="gtk-image-new-from-file">gtk_image_new_from_file()</link>
138 will display a "broken image" graphic &mdash to detect a failed load
140 linkend="gdk-pixbuf-new-from-file">gdk_pixbuf_new_from_file()</link>
142 linkend="gtk-image-new-from-pixbuf">gtk_image_new_from_pixbuf()</link>.
143 </para></footnote>. To load an image for another purpose, use <link
144 linkend="gdk-pixbuf-new-from-file">gdk_pixbuf_new_from_file()</link>.
145 To load an animation, use <link
146 linkend="gdk-pixbuf-animation-new-from-file">gdk_pixbuf_animation_new_from_file()</link>.
148 linkend="gdk-pixbuf-animation-new-from-file">gdk_pixbuf_animation_new_from_file()</link>
149 can also load non-animated images, so use it in combination with
151 linkend="gdk-pixbuf-animation-is-static-image">gdk_pixbuf_animation_is_static_image()</link> to load a file of unknown type.
154 To load an image or animation file asynchronously (without blocking), use
155 <link linkend="GdkPixbufLoader">GdkPixbufLoader</link>.
164 <qandadiv><title>Which widget should I use...</title>
168 ...for lists and trees?
173 See <link linkend="TreeWidget">tree widget overview</link> &mdash you
174 should use the <link linkend="GtkTreeView">GtkTreeView</link> widget.
175 (A list is just a tree with no branches, so the tree widget is used
176 for lists as well.) Do not use the deprecated widgets <link
177 linkend="GtkTree">GtkTree</link> or <link
178 linkend="GtkCList">GtkCList</link>/<link
179 linkend="GtkCTree">GtkCTree</link> in newly-written code, they are
180 less flexible and result in an inferior user interface.
187 ...for multi-line text display or editing?
192 See <link linkend="TextWidget">text widget overview</link> &mdash you
193 should use the <link linkend="GtkTextView">GtkTextView</link> widget.
194 Do not use the deprecated widget <link
195 linkend="GtkText">GtkText</link> in newly-written code, it has a
196 number of problems that are best avoided.
199 If you only have a small amount of text, <link
200 linkend="GtkLabel">GtkLabel</link> may also be appropriate of course.
201 It can be made selectable with <link
202 linkend="gtk-label-set-selectable">
203 gtk_label_set_selectable()</link>. For a single-line text entry,
204 see <link linkend="GtkEntry">GtkEntry</link>.
212 ...to display an image or animation?
217 <link linkend="GtkImage">GtkImage</link> can display images
218 in just about any format GTK+ understands. You can also
219 use <link linkend="GtkDrawingArea">GtkDrawingArea</link> if you need
220 to do something more complex, such as draw text or graphics over the
228 ...for presenting a set of mutually-exclusive choices, where Windows
229 would use a combo box?
234 With GTK+, a <link linkend="GtkOptionMenu">GtkOptionMenu</link> is
235 recommended instead of a combo box, if the user is selecting from a
236 fixed set of options. That is, non-editable combo boxes are not
237 encouraged. <link linkend="GtkOptionMenu">GtkOptionMenu</link> is
238 much easier to use than <link linkend="GtkCombo">GtkCombo</link>
239 as well. Use <link linkend="GtkCombo">GtkCombo</link> only when you
240 need the editable text entry.
243 (As a future enhancement to GTK+, a new widget to replace <link
244 linkend="GtkOptionMenu">GtkOptionMenu</link> and <link
245 linkend="GtkCombo">GtkCombo</link> is planned. This widget will be
246 themeable to look like either a combo box or the current option menu,
247 and will address some shortcomings in the <link
248 linkend="GtkCombo">GtkCombo</link> API. <ulink
249 url="http://bugzilla.gnome.org/show_bug.cgi?id=50554">Bug
250 50554</ulink> tracks this issue, if you want to check status or post
258 <qandadiv><title><link linkend="GtkWidget">GtkWidget</link></title>
262 How do I change the color of a widget?
266 See <link linkend="gtk-widget-modify-fg">gtk_widget_modify_fg()</link>,
267 <link linkend="gtk-widget-modify-bg">gtk_widget_modify_bg()</link>,
268 <link linkend="gtk-widget-modify-base">gtk_widget_modify_base()</link>,
270 linkend="gtk-widget-modify-text">gtk_widget_modify_text()</link>. See
271 <link linkend="gtk-Resource-Files">GTK+ resource files</link> for more
272 discussion. You can also change widget color by installing a resource
273 file and parsing it with <link
274 linkend="gtk-rc-add-default-file">gtk_rc_add_default_file()</link>.
275 The advantage of a resource file is that users can then override the
279 <para>To change the background color for widgets such as <link
280 linkend="GtkLabel">GtkLabel</link> that have no background, place them
281 in a <link linkend="GtkEventBox">GtkEventBox</link> and set the
282 background of the event box.
288 How do I disable/ghost/desensitize a widget?
291 <answer><para> In GTK+ a disabled widget is termed "insensitive." See
293 linkend="gtk-widget-set-sensitive">gtk_widget_set_sensitive()</link>.
300 <qandadiv><title><link linkend="GtkTextView">GtkTextView</link></title>
304 How do I get the contents of the entire text widget as a string?
310 linkend="gtk-text-buffer-get-bounds">gtk_text_buffer_get_bounds()</link>
312 linkend="gtk-text-buffer-get-text">gtk_text_buffer_get_text()</link>
314 linkend="gtk-text-iter-get-text">gtk_text_iter_get_text()</link>.
317 <informalexample><programlisting>
318 GtkTextIter start, end;
319 GtkTextBuffer *buffer;
322 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
323 gtk_text_buffer_get_bounds (buffer, &start, &end);
324 text = gtk_text_iter_get_text (&start, &end);
327 </programlisting></informalexample>
335 <qandadiv><title><link linkend="GtkTreeView">GtkTreeView</link></title>
339 How do I associate some data with a row in the tree?
344 Remember that the <link linkend="GtkTreeModel">GtkTreeModel</link>
345 columns don't necessarily have to be displayed. So you can put
346 non-user-visible data in your model just like any other data, and
347 retrieve it with <link
348 linkend="gtk-tree-model-get">gtk_tree_model_get()</link>.
349 See the <link linkend="TreeWidget">tree widget overview</link>.
356 How do I put an image and some text in the same column?
361 You can pack more than one <link
362 linkend="GtkCellRenderer">GtkCellRenderer</link> into a single
363 <link linkend="GtkTreeViewColumn">GtkTreeViewColumn</link> using
365 linkend="gtk-tree-view-column-pack-start">gtk_tree_view_column_pack_start()</link> or <link linkend="gtk-tree-view-column-pack-end">gtk_tree_view_column_pack_end()</link>. So pack both a <link
366 linkend="GtkCellRendererPixbuf">GtkCellRendererPixbuf</link>
368 linkend="GtkCellRendererText">GtkCellRendererText</link> into the