gtk-question-index.html
来自「最新gtk中文资料集」· HTML 代码 · 共 1,276 行 · 第 1/4 页
HTML
1,276 行
<td align="left" valign="top"><p>How do I make a text view scroll to the end of the buffer automatically ?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>A good way to keep a text buffer scrolled to the end is to place a<a class="link" href="GtkTextMark.html" title="GtkTextMark">mark</a> at the end of the buffer, andgive it right gravity. The gravity has the effect that text insertedat the mark gets inserted <span class="emphasis"><em>before</em></span>, keeping the markat the end. </p><p> To ensure that the end of the buffer remains visible, use<a class="link" href="GtkTextView.html#gtk-text-view-scroll-to-mark"><code class="function">gtk_text_view_scroll_to_mark()</code></a> to scroll to the mark afterinserting new text.</p><p>The gtk-demo application contains an example of this technique. </p></td></tr><tr class="qandadiv"><td align="left" valign="top" colspan="2"><h5 class="title"><a name="id3138336"></a>5. <a class="link" href="GtkTreeView.html" title="GtkTreeView"><span class="type">GtkTreeView</span></a></h5></td></tr><tr class="question"><td align="left" valign="top"><a name="id3138345"></a><a name="id3138347"></a><p><b>5.1.</b></p></td><td align="left" valign="top"><p>How do I associate some data with a row in the tree?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>Remember that the <a class="link" href="GtkTreeModel.html" title="GtkTreeModel"><span class="type">GtkTreeModel</span></a> columns don't necessarily have to be displayed. So you can put non-user-visible data in your model just like any other data, and retrieve it with <a class="link" href="GtkTreeModel.html#gtk-tree-model-get"><code class="function">gtk_tree_model_get()</code></a>. See the <a class="link" href="TreeWidget.html" title="Tree and List Widget Overview">tree widget overview</a>.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3138382"></a><a name="id3138384"></a><p><b>5.2.</b></p></td><td align="left" valign="top"><p>What's the <a class="link" href="GtkTreeView.html" title="GtkTreeView"><span class="type">GtkTreeView</span></a> equivalent of <a class="link" href="GtkCList.html#gtk-clist-find-row-from-data"><code class="function">gtk_clist_find_row_from_data()</code></a>?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>As there is no separate data column in the <a class="link" href="GtkTreeModel.html" title="GtkTreeModel"><span class="type">GtkTreeModel</span></a>, 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<a class="link" href="GtkTreeModel.html#gtk-tree-model-foreach"><code class="function">gtk_tree_model_foreach()</code></a>.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3138430"></a><a name="id3138432"></a><p><b>5.3.</b></p></td><td align="left" valign="top"><p>How do I put an image and some text in the same column?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>You can pack more than one <a class="link" href="GtkCellRenderer.html" title="GtkCellRenderer"><span class="type">GtkCellRenderer</span></a> into a single <a class="link" href="GtkTreeViewColumn.html" title="GtkTreeViewColumn"><span class="type">GtkTreeViewColumn</span></a> using <a class="link" href="GtkTreeViewColumn.html#gtk-tree-view-column-pack-start"><code class="function">gtk_tree_view_column_pack_start()</code></a> or <a class="link" href="GtkTreeViewColumn.html#gtk-tree-view-column-pack-end"><code class="function">gtk_tree_view_column_pack_end()</code></a>. So pack both a <a class="link" href="GtkCellRendererPixbuf.html" title="GtkCellRendererPixbuf"><span class="type">GtkCellRendererPixbuf</span></a> and a <a class="link" href="GtkCellRendererText.html" title="GtkCellRendererText"><span class="type">GtkCellRendererText</span></a> into the column.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3138492"></a><a name="id3138494"></a><p><b>5.4.</b></p></td><td align="left" valign="top"><p>I can set data easily on my <a class="link" href="GtkTreeStore.html" title="GtkTreeStore"><span class="type">GtkTreeStore</span></a>/<a class="link" href="GtkListStore.html" title="GtkListStore"><span class="type">GtkListStore</span></a> models using <a class="link" href="GtkListStore.html#gtk-list-store-set"><code class="function">gtk_list_store_set()</code></a> and <a class="link" href="GtkTreeStore.html#gtk-tree-store-set"><code class="function">gtk_tree_store_set()</code></a>, but can't read it back?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>Both the <a class="link" href="GtkTreeStore.html" title="GtkTreeStore"><span class="type">GtkTreeStore</span></a> and the <a class="link" href="GtkListStore.html" title="GtkListStore"><span class="type">GtkListStore</span></a> implement the <a class="link" href="GtkTreeModel.html" title="GtkTreeModel"><span class="type">GtkTreeModel</span></a>interface. Consequentially, the can use any function this interface implements. The easiest way to read a set of data back is to use <a class="link" href="GtkTreeModel.html#gtk-tree-model-get"><code class="function">gtk_tree_model_get()</code></a>.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3138565"></a><a name="id3138567"></a><p><b>5.5.</b></p></td><td align="left" valign="top"><p>How do I change the way that numbers are formatted by <a class="link" href="GtkTreeView.html" title="GtkTreeView"><span class="type">GtkTreeView</span></a>?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>Use <a class="link" href="GtkTreeView.html#gtk-tree-view-insert-column-with-data-func"><code class="function">gtk_tree_view_insert_column_with_data_func()</code></a>or <a class="link" href="GtkTreeViewColumn.html#gtk-tree-view-column-set-cell-data-func"><code class="function">gtk_tree_view_column_set_cell_data_func()</code></a> and do the conversion from inumber to string yourself (with, say, <ahref="/usr/share/gtk-doc/html/glib/glib-String-Utility-Functions.html#g-strdup-printf"><code class="function">g_strdup_printf()</code></a>).</p><p>The following example demonstrates this:</p><div class="informalexample"><pre class="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);}</pre></div><p></p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3138636"></a><a name="id3138639"></a><p><b>5.6.</b></p></td><td align="left" valign="top"><p>How do I hide the expander arrows in my tree view ?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>Set the expander-column property of the tree view to a hidden column.See <a class="link" href="GtkTreeView.html#gtk-tree-view-set-expander-column"><code class="function">gtk_tree_view_set_expander_column()</code></a> and <a class="link" href="GtkTreeViewColumn.html#gtk-tree-view-column-set-visible"><code class="function">gtk_tree_view_column_set_visible()</code></a>.</p></td></tr><tr class="qandadiv"><td align="left" valign="top" colspan="2"><h5 class="title"><a name="id3138704"></a>6. Using cairo with GTK+</h5></td></tr><tr class="question"><td align="left" valign="top"><a name="id3138709"></a><a name="id3138711"></a><p><b>6.1.</b></p></td><td align="left" valign="top"><p>How do I use cairo to draw in GTK+ applications ?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>USe <ahref="/usr/share/gtk-doc/html/gdk/gdk-Cairo-Interaction.html#gdk-cairo-create"><code class="function">gdk_cairo_create()</code></a> to obtain a cairo context for drawingon a GDK window or pixmap. See <ahref="/usr/share/gtk-doc/html/gdk/gdk-Cairo-Interaction.html">Cairo Interaction</a> for some more useful functions.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3138737"></a><a name="id3138739"></a><p><b>6.2.</b></p></td><td align="left" valign="top"><p>I have created a cairo context with <ahref="/usr/share/gtk-doc/html/gdk/gdk-Cairo-Interaction.html#gdk-cairo-create"><code class="function">gdk_cairo_create()</code></a>, but when Ilater use it, my drawing does not show up. Why is that ?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>All drawing in GTK+ is normally done in an expose handler, and GTK+creates a temporary pixmap for double-buffering the drawing. If you create a cairo context outside the expose handler, it is backedby the GDK window itself, not the double-buffering pixmap. Consequently,any drawing you do with that cairo context gets overwritten at the end of the expose handler, when the double-buffering pixmap is copiedback.</p><p>Possible solutions to this problem are:</p><div class="itemizedlist"><ul type="disc"><li><p>Turn off double-buffering, with <a class="link" href="GtkWidget.html#gtk-widget-set-double-buffered"><code class="function">gtk_widget_set_double_buffered()</code></a>.This is not ideal, since it can cause some flickering.</p></li><li><p>Create the cairo context inside the expose handler. If you do this,<code class="function">gdk_create_cairo()</code> arranges for it to be backed by the double-buffering pixmap. This is the preferred solution, and is used throughout GTK+itself.</p></li></ul></div><p></p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3136473"></a><a name="id3136475"></a><p><b>6.3.</b></p></td><td align="left" valign="top"><p>Can I improve the performance of my application by using theGlitz backend of cairo ?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>No. The GDK X11 backend uses the cairo X backend (and the otherGDK backends use their respective native cairo backends). TheGTK+ developers believe that the best way to improving the GDKdrawing performance is to optimize the cairo X backend and therelevant code paths in the X server that is uses (mostly theRender extension).</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3136492"></a><a name="id3136494"></a><p><b>6.4.</b></p></td><td align="left" valign="top"><p>Can I use cairo to draw on a <ahref="/usr/share/gtk-doc/html/gdk-pixbuf/gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf"><span class="type">GdkPixbuf</span></a> ?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>No, at least not yet. The cairo image surface does not support thepixel format used by GdkPixbuf. </p></td></tr></tbody></table></div></div><div class="footnotes"><br><hr width="100" align="left"><div class="footnote"><p><sup>[<a name="ftn.id3137402" href="#id3137402" class="para">1</a>] </sup> If the file load fails, <a class="link" href="GtkImage.html#gtk-image-new-from-file"><code class="function">gtk_image_new_from_file()</code></a> will display no image graphic — to detect a failed load yourself, use <ahref="/usr/share/gtk-doc/html/gdk-pixbuf/gdk-pixbuf-file-loading.html#gdk-pixbuf-new-from-file"><code class="function">gdk_pixbuf_new_from_file()</code></a> directly, then <a class="link" href="GtkImage.html#gtk-image-new-from-pixbuf"><code class="function">gtk_image_new_from_pixbuf()</code></a>.</p></div></div></div></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?