Common Questions3Common QuestionsCommon Questions
Find answers to common questions in the GTK+ manual
Questions and Answers
This is an "index" of the reference manual organized by common "How do
I..." questions. If you aren't sure which documentation to read for
the question you have, this list is a good place to start.
General
Where can I get help with GTK+, submit a bug report, or make a feature
request?
See the documentation on this topic.
How do I port from one GTK+
version to another?
See the list of incompatible changes
from 1.2 to 2.0. Also, the GNOME 2.0 porting
guide on http://developer.gnome.org
has some more detailed discussion of porting from 1.2 to 2.0.
You may also find useful information in the documentation for
specific widgets and functions.
If you have a question not covered in the manual, feel free to
ask on the mailing lists and please file a bug report against the
documentation.
How does memory management work in GTK+? Should I free data returned
from functions?
See the documentation for GObject and
GtkObject. For GObject note specifically g_object_ref() and g_object_unref(). GtkObject is a subclass of GObject so the same points apply, except that
it has a "floating" state (explained in its documentation).
For strings returned from functions, they will be declared "const"
(using G_CONST_RETURN) if they
should not be freed. Non-const strings should be freed with g_free(). Arrays follow the same rule. (If
you find an exception to the rules, please report a bug to http://bugzilla.gnome.org.)
How do I use GTK+ with threads?
This is covered in the
GDK threads documentation.
See also the GThread documentation for portable
threading primitives.
GtkWidget
How do I change the color of a widget?
See gtk_widget_modify_fg(),
gtk_widget_modify_bg(),
gtk_widget_modify_base(),
and gtk_widget_modify_text(). See
GTK+ resource files for more
discussion. You can also change widget color by installing a resource
file and parsing it with gtk_rc_add_default_file().
The advantage of a resource file is that users can then override the
color you've chosen.
To change the background color for widgets such as GtkLabel that have no background, place them
in a GtkEventBox and set the
background of the event box.
How do I disable/ghost/desensitize a widget?
In GTK+ a disabled widget is termed "insensitive." See
gtk_widget_set_sensitive().
GtkTextView
How do I get the contents of the entire text widget as a string?
See gtk_text_buffer_get_bounds()
and gtk_text_buffer_get_text()
or gtk_text_iter_get_text().
GtkTextIter start, end;
GtkTextBuffer *buffer;
char *text;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
gtk_text_buffer_get_bounds (buffer, &start, &end);
text = gtk_text_iter_get_text (&start, &end);
/* use text */
g_free (text);