?? question_index.sgml
字號:
<link linkend="gtk-widget-modify-bg">gtk_widget_modify_bg()</link>,<link linkend="gtk-widget-modify-base">gtk_widget_modify_base()</link>,and <linklinkend="gtk-widget-modify-text">gtk_widget_modify_text()</link>. See<link linkend="gtk-Resource-Files">GTK+ resource files</link> for morediscussion. You can also change widget color by installing a resourcefile and parsing it with <linklinkend="gtk-rc-add-default-file">gtk_rc_add_default_file()</link>.The advantage of a resource file is that users can then override thecolor you've chosen.</para><para>To change the background color for widgets such as <linklinkend="GtkLabel">GtkLabel</link> that have no background, place themin a <link linkend="GtkEventBox">GtkEventBox</link> and set thebackground of the event box. </para></answer></qandaentry><qandaentry><question><para>How do I change the font of a widget?</para></question><answer><para>This has several possible answers, depending on what exactly you want toachieve. One option is <linklinkend="gtk-widget-modify-font">gtk_widget_modify_font()</link>. Note that this function can be used to change only the font size, as in the following example:<programlisting> PangoFontDesc *font_desc = pango_font_description_new (); pango_font_description_set_size (font_desc, 40); gtk_widget_modify_font (widget, font); pango_font_description_free (font_desc);</programlisting></para><para>If you want to make the text of a label larger, you can use <linklinkend="gtk-label-set-markup">gtk_label_set_markup()</link>:<programlisting>gtk_label_set_markup (label, "<big>big text</big>");</programlisting>This is preferred for many apps because it's a relative size to the user's chosen font size. See <link linkend="g-markup-escape-text">g_markup_escape_text()</link> if you are constructing such strings on the fly.</para><para>You can also change the font of a widget by putting<programlisting> gtk-font-name = "Sans 30"</programlisting>in a resource file and parsing it with <linklinkend="gtk-rc-add-default-file">gtk_rc_add_default_file()</link>.The advantage of a resource file is that users can then override thefont you've chosen. See<link linkend="gtk-Resource-Files">GTK+ resource files</link> for morediscussion. </para></answer></qandaentry><qandaentry><question><para>How do I disable/ghost/desensitize a widget?</para></question><answer><para> In GTK+ a disabled widget is termed "insensitive." See<linklinkend="gtk-widget-set-sensitive">gtk_widget_set_sensitive()</link>.</para></answer></qandaentry></qandadiv><qandadiv><title><link linkend="GtkTextView">GtkTextView</link></title><qandaentry><question><para>How do I get the contents of the entire text widget as a string?</para></question><answer><para>See <link linkend="gtk-text-buffer-get-bounds">gtk_text_buffer_get_bounds()</link> and <link linkend="gtk-text-buffer-get-text">gtk_text_buffer_get_text()</link>or <link linkend="gtk-text-iter-get-text">gtk_text_iter_get_text()</link>.</para><para><informalexample><programlisting> 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);</programlisting></informalexample></para></answer></qandaentry><qandaentry><question><para>How do I make a text widget display its complete contents in a specific font?</para></question><answer><para>If you use <link linkend="gtk-text-buffer-insert-with-tags">gtk_text_buffer_insert_with_tags()</link> with appropriate tags to select the font, the inserted text will have the desired appearance, but text typed in by the user before or after the tagged block will appear in the default style. </para><para>To ensure that all text has the desired appearance, use <link linkend="gtk-widget-modify-font">gtk_widget_modify_font()</link> to change the default font for the widget.</para></answer></qandaentry><qandaentry><question><para>How do I make a text view scroll to the end of the buffer automatically ?</para></question><answer><para>The "insert" <link linkend="GtkTextMark">mark</link> marks the insertion pointwhere <link linkend="gtk-text-buffer-insert">gtk_text_buffer_insert()</link>inserts new text into the buffer. The text is inserted <emphasis>before</emphasis> the "insert" mark, so that it generally stays at the end of the buffer. If it gets explicitly moved to some other position, e.g. when the user selects some text, use <link linkend="gtk-text-buffer-move-mark">gtk_text_buffer_move_mark()</link>to set it to the desired location before inserting more text. The "insert" mark of a buffer can be obtained with <linklinkend="gtk-text-buffer-get-insert">gtk_text_buffer_get_insert()</link>.</para><para> To ensure that the end of the buffer remains visible, use<link linkend="gtk-text-view-scroll-to-mark">gtk_text_view_scroll_to_mark()</link> to scroll to the "insert" mark after inserting new text.</para></answer></qandaentry></qandadiv><qandadiv><title><link linkend="GtkTreeView">GtkTreeView</link></title><qandaentry><question><para>How do I associate some data with a row in the tree?</para></question><answer><para>Remember that the <link linkend="GtkTreeModel">GtkTreeModel</link>columns don't necessarily have to be displayed. So you can putnon-user-visible data in your model just like any other data, andretrieve it with <linklinkend="gtk-tree-model-get">gtk_tree_model_get()</link>.See the <link linkend="TreeWidget">tree widget overview</link>.</para></answer></qandaentry><qandaentry><question><para>What's the <link linkend="GtkTreeView">GtkTreeView</link> equivalent of <link linkend="gtk-clist-find-row-from-data">gtk_clist_find_row_from_data()</link>?</para></question><answer><para>As there is no separate data column in the <link linkend="GtkTreeModel">GtkTreeModel</link>, there's nobuilt in function to find the iter from data. You can write a customsearching function to walk the tree and find the data, or use<link linkend="gtk-tree-model-foreach">gtk_tree_model_foreach()</link>.</para></answer></qandaentry><qandaentry><question><para>How do I put an image and some text in the same column?</para></question><answer><para>You can pack more than one <linklinkend="GtkCellRenderer">GtkCellRenderer</link> into a single<link linkend="GtkTreeViewColumn">GtkTreeViewColumn</link> using<link 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 <linklinkend="GtkCellRendererPixbuf">GtkCellRendererPixbuf</link>and a <linklinkend="GtkCellRendererText">GtkCellRendererText</link> into thecolumn.</para></answer></qandaentry><qandaentry><question><para>I can set data easily on my <link linkend="GtkTreeStore">GtkTreeStore</link>/<link linkend="GtkListStore">GtkListStore</link> models using <linklinkend="gtk-tree-model-get">gtk_list_store_set()</link> and <linklinkend="gtk-tree-model-get">gtk_tree_store_set()</link>, but can't read it back?</para></question><answer><para>Both the <link linkend="GtkTreeStore">GtkTreeStore</link> and the <link linkend="GtkListStore">GtkListStore</link> implement the <link linkend="GtkTreeModel">GtkTreeModel</link> interface. Consequentially, the can use any function this interface implements. The easiest way to read a set of data back is to use <linklinkend="gtk-tree-model-get">gtk_tree_model_get()</link>.</para></answer></qandaentry><qandaentry><question><para>How do I change the way that numbers are formatted by <link linkend="GtkTreeView">GtkTreeView</link>?</para></question><answer><para>Use <link linkend="gtk-tree-view-insert-column-with-data-func">gtk_tree_view_insert_column_with_data_func()</link> or <link linkend="gtk-tree-view-column-set-cell-data-func">gtk_tree_view_column_set_cell_data_func()</link>and do the conversion from number to string yourself (with, say, <link linkend="g-strdup-printf">g_strdup_printf()</link>).</para><para>The following example demonstrates this:<informalexample><programlisting>enum { DOUBLE_COLUMN, N_COLUMNS};GtkListStore *mycolumns;GtkTreeView *treeview;void my_cell_double_to_text (GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data){ GtkCellRendererText *cell_text = (GtkCellRendererText *)cell; gdouble d; gchar *text; /* Get the double value from the model. */ gtk_tree_model_get (tree_model, iter, (gint)data, &d, -1); /* Now we can format the value ourselves. */ text = g_strdup_printf ("%.2f", d); g_object_set (cell, "text", text, NULL); g_free (text);}void set_up_new_columns (GtkTreeView *myview){ GtkCellRendererText *renderer; GtkTreeViewColumn *column; GtkListStore *mycolumns; /* Create the data model and associate it with the given TreeView */ mycolumns = gtk_list_store_new (N_COLUMNS, G_TYPE_DOUBLE); gtk_tree_view_set_model (myview, GTK_TREE_MODEL (mycolumns)); /* Create a GtkCellRendererText */ renderer = gtk_cell_renderer_text_new (); /* Create a new column that has a title ("Example column"), * uses the above created renderer that will render the double * value into text from the associated model's rows. */ column = gtk_tree_view_column_new (); gtk_tree_view_column_set_title (column, "Example column"); renderer = gtk_cell_renderer_text_new (); gtk_tree_view_column_pack_start (column, renderer, TRUE); /* Append the new column after the GtkTreeView's previous columns. */ gtk_tree_view_append_column (GTK_TREE_VIEW (myview), column); /* Since we created the column by hand, we can set it up for our * needs, e.g. set its minimum and maximum width, etc. */ /* Set up a custom function that will be called when the column content * is rendered. We use the func_data pointer as an index into our * model. This is convenient when using multi column lists. */ gtk_tree_view_column_set_cell_data_func (column, renderer, my_cell_double_to_text, (gpointer)DOUBLE_COLUMN, NULL);}</programlisting></informalexample></para></answer></qandaentry></qandadiv></qandaset></refsect1></refentry>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -