gtk-question-index.html
来自「最新gtk中文资料集」· HTML 代码 · 共 1,276 行 · 第 1/4 页
HTML
1,276 行
See also the "Text Handling in GTK 2" section of <a class="ulink" href="http://developer.gnome.org/dotplan/porting/" target="_top">Porting applications to the GNOME 2.0 platform</a>.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3137638"></a><a name="id3137640"></a><p><b>1.14.</b></p></td><td align="left" valign="top"><p>Why are types not registered if I use their <code class="literal">GTK_TYPE_BLAH</code> macro ?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>The <code class="literal">GTK_TYPE_BLAH</code> macros are defined as calls to <code class="literal"><code class="function">gtk_blah_get_type()</code></code>, and the <code class="literal"><code class="function">_get_type()</code></code> ifunctions are declared as <ahref="/usr/share/gtk-doc/html/glib/glib-Miscellaneous-Macros.html#G-GNUC-CONST:CAPS"><code class="literal">G_GNUC_CONST</code></a> which allows the compiler to optimizethe call away if it appears that the value is not being used.</p><p>A common workaround for this problem is to store the result in a volatile variable, which keeps the compiler from optimizing the call away.</p><div class="informalexample"><pre class="programlisting">volatile GType dummy = GTK_TYPE_BLAH;</pre></div><p></p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3137712"></a><a name="id3137714"></a><p><b>1.15.</b></p></td><td align="left" valign="top"><p>How do I create a transparent toplevel window ?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>To make a window transparent, it needs to use a visual which supports that.This is done by getting the RGBA colormap of the screen with <ahref="/usr/share/gtk-doc/html/gdk/GdkScreen.html#gdk-screen-get-rgba-colormap"><code class="function">gdk_screen_get_rgba_colormap()</code></a> and setting it on the window. Note that<ahref="/usr/share/gtk-doc/html/gdk/GdkScreen.html#gdk-screen-get-rgba-colormap"><code class="function">gdk_screen_get_rgba_colormap()</code></a> will return <ahref="/usr/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL:CAPS"><code class="literal">NULL</code></a> if transparent windowsare not supported on the screen; also note that this may change fromscreen to screen, so it needs to be repeated whenever the window is movedto a different screen.</p><div class="informalexample"><pre class="programlisting">GdkColormap *colormap;colormap = gdk_screen_get_rgba_colormap (screen);if (!colormap) colormap = gtk_screen_get_rgb_colormap (screen);gtk_widget_set_colormap (widget, colormap);</pre></div><p>One possibility to fill the alpha channel on the window is to use<ahref="/usr/share/gtk-doc/html/gdk/gdk-GdkRGB.html#gdk-draw-rgb-32-image"><code class="function">gdk_draw_rgb_32_image()</code></a>.</p><p>Note that the presence of an RGBA visual is no guarantee that thewindow will actually appear transparent on screen. On X11, this requires a compositing manager to be running. See <a class="link" href="GtkWidget.html#gtk-widget-is-composited"><code class="function">gtk_widget_is_composited()</code></a> for a way to find out if the alphachannel will be respected.</p></td></tr><tr class="qandadiv"><td align="left" valign="top" colspan="2"><h5 class="title"><a name="id3137800"></a>2. Which widget should I use...</h5></td></tr><tr class="question"><td align="left" valign="top"><a name="id3137805"></a><a name="id3137807"></a><p><b>2.1.</b></p></td><td align="left" valign="top"><p>...for lists and trees?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>See <a class="link" href="TreeWidget.html" title="Tree and List Widget Overview">tree widget overview</a> — youshould use the <a class="link" href="GtkTreeView.html" title="GtkTreeView"><span class="type">GtkTreeView</span></a> widget. (A list is just a tree with no branches, so the tree widget is used for lists as well.) Do not use the deprecated widgets <a class="link" href="GtkTree.html" title="GtkTree"><span class="type">GtkTree</span></a> or <a class="link" href="GtkCList.html" title="GtkCList"><span class="type">GtkCList</span></a>/<a class="link" href="GtkCTree.html" title="GtkCTree"><span class="type">GtkCTree</span></a> in newly-written code, they areless flexible and result in an inferior user interface.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3137853"></a><a name="id3137855"></a><p><b>2.2.</b></p></td><td align="left" valign="top"><p>...for multi-line text display or editing?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>See <a class="link" href="TextWidget.html" title="Text Widget Overview">text widget overview</a> — youshould use the <a class="link" href="GtkTextView.html" title="GtkTextView"><span class="type">GtkTextView</span></a> widget. Do not use the deprecated widget <a class="link" href="GtkText.html" title="GtkText"><span class="type">GtkText</span></a> in newly-written code, it has a number of problems that are best avoided.</p><p>If you only have a small amount of text, <a class="link" href="GtkLabel.html" title="GtkLabel"><span class="type">GtkLabel</span></a> may also be appropriate of course. It can be made selectable with <a class="link" href="GtkLabel.html#gtk-label-set-selectable"><code class="function">gtk_label_set_selectable()</code></a>. For a single-line text entry, see <a class="link" href="GtkEntry.html" title="GtkEntry"><span class="type">GtkEntry</span></a>.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3137915"></a><a name="id3137917"></a><p><b>2.3.</b></p></td><td align="left" valign="top"><p>...to display an image or animation?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p><a class="link" href="GtkImage.html" title="GtkImage"><span class="type">GtkImage</span></a> can display images in just about any format GTK+ understands. You can also use <a class="link" href="GtkDrawingArea.html" title="GtkDrawingArea"><span class="type">GtkDrawingArea</span></a> if you need to do something more complex, such as draw text or graphics over the top of the image.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3137945"></a><a name="id3137947"></a><p><b>2.4.</b></p></td><td align="left" valign="top"><p>...for presenting a set of mutually-exclusive choices, where Windowswould use a combo box?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>With GTK+, a <a class="link" href="GtkComboBox.html" title="GtkComboBox"><span class="type">GtkComboBox</span></a> is the recommended widget to use for this use case.This widget looks like either a combo box or the current option menu, dependingon the current theme. If you need an editable text entry, use <a class="link" href="GtkComboBoxEntry.html" title="GtkComboBoxEntry"><span class="type">GtkComboBoxEntry</span></a>.</p></td></tr><tr class="qandadiv"><td align="left" valign="top" colspan="2"><h5 class="title"><a name="id3137978"></a>3. <a class="link" href="GtkWidget.html" title="GtkWidget"><span class="type">GtkWidget</span></a></h5></td></tr><tr class="question"><td align="left" valign="top"><a name="id3137986"></a><a name="id3137988"></a><p><b>3.1.</b></p></td><td align="left" valign="top"><p>How do I change the color of a widget?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>See <a class="link" href="GtkWidget.html#gtk-widget-modify-fg"><code class="function">gtk_widget_modify_fg()</code></a>, <a class="link" href="GtkWidget.html#gtk-widget-modify-bg"><code class="function">gtk_widget_modify_bg()</code></a>, <a class="link" href="GtkWidget.html#gtk-widget-modify-base"><code class="function">gtk_widget_modify_base()</code></a>,and <a class="link" href="GtkWidget.html#gtk-widget-modify-text"><code class="function">gtk_widget_modify_text()</code></a>. See <a class="link" href="gtk-Resource-Files.html" title="Resource Files">GTK+ resource files</a> for more discussion. You can also change widget color by installing a resource file and parsing it with <a class="link" href="gtk-Resource-Files.html#gtk-rc-add-default-file"><code class="function">gtk_rc_add_default_file()</code></a>.The advantage of a resource file is that users can then override thecolor you've chosen.</p><p>To change the background color for widgets such as <a class="link" href="GtkLabel.html" title="GtkLabel"><span class="type">GtkLabel</span></a> that have no background, place them in a <a class="link" href="GtkEventBox.html" title="GtkEventBox"><span class="type">GtkEventBox</span></a> and set the background of the event box. </p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3138067"></a><a name="id3138069"></a><p><b>3.2.</b></p></td><td align="left" valign="top"><p>How do I change the font of a widget?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>This has several possible answers, depending on what exactly you want to achieve. One option is <a class="link" href="GtkWidget.html#gtk-widget-modify-font"><code class="function">gtk_widget_modify_font()</code></a>. Note that this function can be used to change only the font size, as in the following example:</p><pre class="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);</pre><p></p><p>If you want to make the text of a label larger, you can use <a class="link" href="GtkLabel.html#gtk-label-set-markup"><code class="function">gtk_label_set_markup()</code></a>:</p><pre class="programlisting">gtk_label_set_markup (label, "<big>big text</big>");</pre><p>This is preferred for many apps because it's a relative size to the user's chosen font size. See <ahref="/usr/share/gtk-doc/html/glib/glib-Simple-XML-Subset-Parser.html#g-markup-escape-text"><code class="function">g_markup_escape_text()</code></a> if you are constructing such strings on the fly.</p><p>You can also change the font of a widget by putting</p><pre class="programlisting"> gtk-font-name = "Sans 30"</pre><p>in a resource file and parsing it with <a class="link" href="gtk-Resource-Files.html#gtk-rc-add-default-file"><code class="function">gtk_rc_add_default_file()</code></a>. The advantage of a resource file is that users can then override the font youhave chosen. See <a class="link" href="gtk-Resource-Files.html" title="Resource Files">GTK+ resource files</a> for more discussion. </p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3138160"></a><a name="id3138162"></a><p><b>3.3.</b></p></td><td align="left" valign="top"><p>How do I disable/ghost/desensitize a widget?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p> In GTK+ a disabled widget is termed "insensitive." See<a class="link" href="GtkWidget.html#gtk-widget-set-sensitive"><code class="function">gtk_widget_set_sensitive()</code></a>.</p></td></tr><tr class="qandadiv"><td align="left" valign="top" colspan="2"><h5 class="title"><a name="id3138183"></a>4. <a class="link" href="GtkTextView.html" title="GtkTextView"><span class="type">GtkTextView</span></a></h5></td></tr><tr class="question"><td align="left" valign="top"><a name="id3138191"></a><a name="id3138193"></a><p><b>4.1.</b></p></td><td align="left" valign="top"><p>How do I get the contents of the entire text widget as a string?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>See <a class="link" href="GtkTextBuffer.html#gtk-text-buffer-get-bounds"><code class="function">gtk_text_buffer_get_bounds()</code></a> and <a class="link" href="GtkTextBuffer.html#gtk-text-buffer-get-text"><code class="function">gtk_text_buffer_get_text()</code></a>or <a class="link" href="gtk-GtkTextIter.html#gtk-text-iter-get-text"><code class="function">gtk_text_iter_get_text()</code></a>.</p><p></p><div class="informalexample"><pre class="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);</pre></div><p></p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3138245"></a><a name="id3138247"></a><p><b>4.2.</b></p></td><td align="left" valign="top"><p>How do I make a text widget display its complete contents in a specific font?</p></td></tr><tr class="answer"><td align="left" valign="top"></td><td align="left" valign="top"><p>If you use <a class="link" href="GtkTextBuffer.html#gtk-text-buffer-insert-with-tags"><code class="function">gtk_text_buffer_insert_with_tags()</code></a> 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. </p><p>To ensure that all text has the desired appearance, use <a class="link" href="GtkWidget.html#gtk-widget-modify-font"><code class="function">gtk_widget_modify_font()</code></a> to change the default font for the widget.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id3138285"></a><a name="id3138287"></a><p><b>4.3.</b></p></td>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?