0

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

Damn Vegetables
  • 11,484
  • 13
  • 80
  • 135

1 Answers1

0

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

MaxPlankton
  • 1,158
  • 14
  • 28
  • I think I have got the gist, but there still are some weird things. (1)the row editor shows up for GtkListStore, but not GtkTreeStore, which I was using. (2)the name column (gchararray) does not show up in the designer but shows up in the preview. (3)the "column type" text is black under a dark theme, which makes the text difficult to read. (I have appended the screenshot to my OP) Are these bugs? Glade version 3.40. – Damn Vegetables Dec 21 '22 at 06:33