⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 treewidget.html

📁 最新gtk中文资料集
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"><title>Tree and List Widget Overview</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="GTK+ Reference Manual"><link rel="up" href="TreeWidgetObjects.html" title="Tree, List and Icon Grid Widgets"><link rel="prev" href="TreeWidgetObjects.html" title="Tree, List and Icon Grid Widgets"><link rel="next" href="GtkTreeModel.html" title="GtkTreeModel"><meta name="generator" content="GTK-Doc V1.9 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"><link rel="part" href="gtk.html" title="Part&#160;I.&#160;GTK+ Overview"><link rel="part" href="gtkbase.html" title="Part&#160;II.&#160;GTK+ Core Reference"><link rel="part" href="gtkobjects.html" title="Part&#160;III.&#160;GTK+ Widgets and Objects"><link rel="chapter" href="ch01.html" title="Object Hierarchy"><link rel="chapter" href="ch02.html" title="Widget Gallery"><link rel="chapter" href="WindowWidgets.html" title="Windows"><link rel="chapter" href="DisplayWidgets.html" title="Display Widgets"><link rel="chapter" href="ButtonWidgets.html" title="Buttons and Toggles"><link rel="chapter" href="NumericEntry.html" title="Numeric/Text Data Entry"><link rel="chapter" href="TextWidgetObjects.html" title="Multiline Text Editor"><link rel="chapter" href="TreeWidgetObjects.html" title="Tree, List and Icon Grid Widgets"><link rel="chapter" href="MenusAndCombos.html" title="Menus, Combo Box, Toolbar"><link rel="chapter" href="Actions.html" title="Action-based menus and toolbars"><link rel="chapter" href="SelectorWidgets.html" title="Selectors (File/Font/Color/Input Devices)"><link rel="chapter" href="LayoutContainers.html" title="Layout Containers"><link rel="chapter" href="Ornaments.html" title="Ornaments"><link rel="chapter" href="ScrollingWidgets.html" title="Scrolling"><link rel="chapter" href="Printing.html" title="Printing"><link rel="chapter" href="MiscObjects.html" title="Miscellaneous"><link rel="chapter" href="AbstractObjects.html" title="Abstract Base Classes"><link rel="chapter" href="PlugSocket.html" title="Cross-process Embedding"><link rel="chapter" href="SpecialObjects.html" title="Special-purpose features"><link rel="chapter" href="RecentDocuments.html" title="Recently Used Documents"><link rel="chapter" href="Builder.html" title="Interface builder"><link rel="chapter" href="DeprecatedObjects.html" title="Deprecated"><link rel="part" href="migrating.html" title="Part&#160;IV.&#160;Migrating from Previous Versions of GTK+"><link rel="chapter" href="gtk-migrating-checklist.html" title="Migration Checklist"><link rel="chapter" href="gtk-migrating-GtkFileChooser.html" title="Migrating from GtkFileSelection to GtkFileChooser"><link rel="chapter" href="gtk-migrating-GtkAction.html" title="Migrating from old menu and toolbar systems to GtkAction"><link rel="chapter" href="gtk-migrating-GtkComboBox.html" title="Migrating from GtkOptionMenu and GtkCombo to GtkComboBox and GtkComboBoxEntry"><link rel="chapter" href="gtk-migrating-GtkIconView.html" title="Migrating from GnomeIconList to GtkIconView"><link rel="chapter" href="gtk-migrating-GtkAboutDialog.html" title="Migrating from GnomeAbout to GtkAboutDialog"><link rel="chapter" href="gtk-migrating-GtkColorButton.html" title="Migrating from GnomeColorPicker to GtkColorButton"><link rel="chapter" href="gtk-migrating-GtkAssistant.html" title="Migrating from GnomeDruid to GtkAssistant"><link rel="chapter" href="gtk-migrating-GtkRecentChooser.html" title="Migrating from EggRecent to GtkRecentChooser"><link rel="chapter" href="gtk-migrating-GtkLinkButton.html" title="Migrating from GnomeHRef to GtkLinkButton"><link rel="chapter" href="gtk-migrating-GtkBuilder.html" title="Migrating from libglade to GtkBuilder"><link rel="chapter" href="gtk-migrating-tooltips.html" title="Migrating from GtkTooltips to GtkTooltip"><link rel="part" href="pt05.html" title="Part&#160;V.&#160;GTK+ Tools"><link rel="glossary" href="glossary.html" title="Glossary"><link rel="index" href="ix01.html" title="Index"><link rel="index" href="ix02.html" title="Index of deprecated symbols"><link rel="index" href="ix03.html" title="Index of new symbols in 2.2"><link rel="index" href="ix04.html" title="Index of new symbols in 2.4"><link rel="index" href="ix05.html" title="Index of new symbols in 2.6"><link rel="index" href="ix06.html" title="Index of new symbols in 2.8"><link rel="index" href="ix07.html" title="Index of new symbols in 2.10"><link rel="index" href="ix08.html" title="Index of new symbols in 2.12"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="TreeWidgetObjects.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="TreeWidgetObjects.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">GTK+ Reference Manual</th><td><a accesskey="n" href="GtkTreeModel.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr></table><div class="refentry" lang="en"><a name="TreeWidget"></a><div class="titlepage"></div><div class="refnamediv"><table width="100%"><tr><td valign="top"><h2><span class="refentrytitle">Tree and List Widget Overview</span></h2><p>Tree and List Widget Overview &#8212; Overview of GtkTreeModel, GtkTreeView, and friends</p></td><td valign="top" align="right"></td></tr></table></div><div class="refsect1" lang="en"><a name="id3670103"></a><h2>Overview</h2><p>      To create a tree or list in GTK+, use the <a class="link" href="GtkTreeModel.html" title="GtkTreeModel"><span class="type">GtkTreeModel</span></a> interface in      conjunction with the <a class="link" href="GtkTreeView.html" title="GtkTreeView"><span class="type">GtkTreeView</span></a> widget.  This widget is      designed around a <em class="firstterm">Model/View/Controller</em>      design and consists of four major parts:      </p><table class="simplelist" border="0" summary="Simple list"><tr><td>The tree view widget (<span class="structname">GtkTreeView</span>)</td></tr><tr><td>The view column (<span class="structname">GtkTreeViewColumn</span>)</td></tr><tr><td>The cell renderers (<span class="structname">GtkCellRenderer</span> etc.)</td></tr><tr><td>The model interface (<span class="structname">GtkTreeModel</span>)</td></tr></table><p>      The <span class="emphasis"><em>View</em></span> is composed of the first three	objects, while the last is the <span class="emphasis"><em>Model</em></span>.  One	of the prime benefits of the MVC design is that multiple views	can be created of a single model.  For example, a model mapping	the file system could be created for a file manager.  Many views	could be created to display various parts of the file system,	but only one copy need be kept in memory.    </p><p>        The purpose of the cell renderers is to provide extensibility to the        widget and to allow multiple ways of rendering the same type of data.        For example, consider how to render a boolean variable.  Should it        render it as a string of "True" or "False", "On" or "Off", or should        it be rendered as a checkbox?    </p></div><div class="refsect1" lang="en"><a name="id3670799"></a><h2>Creating a model</h2><p>      GTK+ provides two simple models that can be used: the <a class="link" href="GtkListStore.html" title="GtkListStore"><span class="type">GtkListStore</span></a>      and the <a class="link" href="GtkTreeStore.html" title="GtkTreeStore"><span class="type">GtkTreeStore</span></a>.  GtkListStore is used to model list widgets,       while the GtkTreeStore models trees.  It is possible to develop a new       type of model, but the existing models should be satisfactory for all       but the most specialized of situations.  Creating the model is quite       simple:    </p><div class="informalexample"><pre class="programlisting">GtkListStore *store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);</pre></div><p>      This creates a list store with two columns: a string column and a boolean      column.  Typically the 2 is never passed directly like that; usually an      enum is created wherein the different columns are enumerated, followed by      a token that represents the total number of columns.  The next example will      illustrate this, only using a tree store instead of a list store. Creating      a tree store operates almost exactly the same.    </p><div class="informalexample"><pre class="programlisting">enum{   TITLE_COLUMN,   AUTHOR_COLUMN,   CHECKED_COLUMN,   N_COLUMNS};GtkTreeStore *store = gtk_tree_store_new (N_COLUMNS,       /* Total number of columns */                                          G_TYPE_STRING,   /* Book title              */                                          G_TYPE_STRING,   /* Author                  */                                          G_TYPE_BOOLEAN); /* Is checked out?         */</pre></div><p>      Adding data to the model is done using <a class="link" href="GtkTreeStore.html#gtk-tree-store-set"><code class="function">gtk_tree_store_set()</code></a> or       <a class="link" href="GtkListStore.html#gtk-list-store-set"><code class="function">gtk_list_store_set()</code></a>, depending upon which sort of model was      created.  To do this, a <a class="link" href="GtkTreeModel.html#GtkTreeIter"><span class="type">GtkTreeIter</span></a> must be acquired.  The iterator       points to the location where data will be added.    </p><p>      Once an iterator has been acquired, <a class="link" href="GtkTreeStore.html#gtk-tree-store-set"><code class="function">gtk_tree_store_set()</code></a> is used to      apply data to the part of the model that the iterator points to.        Consider the following example:    </p><div class="informalexample"><pre class="programlisting">GtkTreeIter   iter;gtk_tree_store_append (store, &amp;iter, NULL);  /* Acquire an iterator */gtk_tree_store_set (store, &amp;iter,                    TITLE_COLUMN, "The Principle of Reason",                    AUTHOR_COLUMN, "Martin Heidegger",                    CHECKED_COLUMN, FALSE,                    -1);</pre></div><p>    Notice that the last argument is -1.  This is always done because    this is a variable-argument function and it needs to know when to stop    processing arguments.  It can be used to set the data in any or all    columns in a given row.  </p><p>    The third argument to <a class="link" href="GtkTreeStore.html#gtk-tree-store-append"><code class="function">gtk_tree_store_append()</code></a> is the parent iterator.  It    is used to add a row to a GtkTreeStore as a child of an existing row.  This    means that the new row will only be visible when its parent is visible and    in its expanded state.  Consider the following example:  </p><div class="informalexample"><pre class="programlisting">GtkTreeIter iter1;  /* Parent iter */GtkTreeIter iter2;  /* Child iter  */gtk_tree_store_append (store, &amp;iter1, NULL);  /* Acquire a top-level iterator */gtk_tree_store_set (store, &amp;iter1,                    TITLE_COLUMN, "The Art of Computer Programming",                    AUTHOR_COLUMN, "Donald E. Knuth",                    CHECKED_COLUMN, FALSE,                    -1);gtk_tree_store_append (store, &amp;iter2, &amp;iter1);  /* Acquire a child iterator */gtk_tree_store_set (store, &amp;iter2,                    TITLE_COLUMN, "Volume 1: Fundamental Algorithms",                    -1);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -