Search code examples
gtkglade

Possible to add some static data to TreeView within Glade?


I have seen the existing question but I am not sure if adding actual data in Glade is possible or not.

I have created a TreeView and added two columns. I created a TreeStore and set it to the TreeView. And how can I add some static data like the following within Glade?

Jane 10
Tom  20
Mike 30
Mary 40

enter image description here

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.40.0 -->
<interface>
  <requires lib="gtk+" version="3.18"/>
  <object class="GtkTreeStore" id="treestore1">
    <columns>
      <!-- column-name name -->
      <column type="string"/>
      <!-- column-name age -->
      <column type="int"/>
    </columns>
  </object>
  <object class="GtkWindow" id="MainWindow">
    <property name="can-focus">False</property>
    <property name="title" translatable="yes">Example Window</property>
    <property name="default-width">480</property>
    <property name="default-height">240</property>
    <child>
      <object class="GtkTreeView">
        <property name="visible">True</property>
        <property name="can-focus">True</property>
        <property name="model">treestore1</property>
        <property name="enable-grid-lines">both</property>
        <child internal-child="selection">
          <object class="GtkTreeSelection"/>
        </child>
        <child>
          <object class="GtkTreeViewColumn" id="1">
            <property name="resizable">True</property>
            <property name="sizing">autosize</property>
            <property name="title" translatable="yes">Name</property>
            <property name="clickable">True</property>
            <property name="reorderable">True</property>
            <property name="sort-indicator">True</property>
            <child>
              <object class="GtkCellRendererText">
                <property name="text">Doge</property>
              </object>
            </child>
          </object>
        </child>
        <child>
          <object class="GtkTreeViewColumn" id="2">
            <property name="resizable">True</property>
            <property name="sizing">autosize</property>
            <property name="title" translatable="yes">Age</property>
            <property name="clickable">True</property>
            <property name="reorderable">True</property>
            <property name="sort-indicator">True</property>
            <child>
              <object class="GtkCellRendererText">
                <property name="text">10</property>
              </object>
            </child>
          </object>
        </child>
      </object>
    </child>
  </object>
</interface>

enter image description here


Solution

  • Data are stored in a store, such as GtkListStore, not in the view. To add them, click the store the widget on the glade.

    At the bottom right corner of the image below, there are options to Add and remove rows.

    enter image description here

    Moreover, to associate the view with the store, the Text option in the cell renderer must be set to the corresponding store column.

    enter image description here