1

I have already a GTK+ application. There are a few widgets: GtkWindow, GtkTreeView, GtkListStore. All user interface was created in Glade.

int main( int argc, char **argv )
{
    GtkBuilder *builder;
    GtkWidget *topWindow;
    GtkTreeView *treeView;
    GtkListStore  *treeStore;

    GError *error = NULL;
    gtk_init( &argc, &argv ); 
    builder = gtk_builder_new();
    if( ! gtk_builder_add_from_file( builder, UI_FILE, &error ) )
    {
        g_warning( "%s", error->message );
        g_free( error );
        return( 1 );
    }


   topWindow = GTK_WIDGET(gtk_builder_get_object(builder, "topWindow"));
   treeStore = GTK_LIST_STORE(gtk_builder_get_object(builder, "liststore"));
   treeView = GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeview"));

   entry1 = GTK_ENTRY(gtk_builder_get_object(builder, "entry1"));
   entry2 = GTK_ENTRY(gtk_builder_get_object(builder, "entry2"));
   entry3 = GTK_ENTRY(gtk_builder_get_object(builder, "entry3"));

   gtk_builder_connect_signals (builder, NULL); 
   g_object_unref( G_OBJECT( builder ) );

   gtk_widget_show( topWindow );

   gtk_main();

   return( 0 );
}

The compilation is successful:

igor@igor-desktop:~/proj/TreeView_example$ make
gcc -Wall -g `pkg-config --cflags gtk+-2.0 gmodule-2.0` -c charter.c
gcc `pkg-config --libs gtk+-2.0 gmodule-2.0` charter.o -o charter

When I run the application, I get some warnings:

(charter:3728): GLib-GObject-WARNING **: value "466" of type `gint' is invalid or out of range for property `xalign' of type `gfloat'

(charter:3728): GLib-GObject-WARNING **: value "44" of type `gint' is invalid or out of range for property `xalign' of type `gfloat'

(charter:3728): GLib-GObject-WARNING **: value "466" of type `gint' is invalid or out of range for property `xalign' of type `gfloat'

(charter:3728): GLib-GObject-WARNING **: value "466" of type `gint' is invalid or out of range for property `xalign' of type `gfloat'

(charter:3728): GLib-GObject-WARNING **: value "44" of type `gint' is invalid or out of range for property `xalign' of type `gfloat'

(charter:3728): GLib-GObject-WARNING **: value "44" of type `gint' is invalid or out of range for property `xalign' of type `gfloat'

(charter:3728): GLib-GObject-WARNING **: value "466" of type `gint' is invalid or out of range for property `xalign' of type `gfloat'

(charter:3728): GLib-GObject-WARNING **: value "466" of type `gint' is invalid or out of range for property `xalign' of type `gfloat'

(charter:3728): GLib-GObject-WARNING **: value "44" of type `gint' is invalid or out of range for property `xalign' of type `gfloat'

(charter:3728): GLib-GObject-WARNING **: value "44" of type `gint' is invalid or out of range for property `xalign' of type `gfloat'

This is a part of Glade XML file, which contains the description of GtkTreeView:

 <object class="GtkTreeView" id="treeview">
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="model">liststore</property>
                <property name="search_column">2</property>
                <child>
                  <object class="GtkTreeViewColumn" id="treeviewcolumn1">
                    <property name="title">&#x418;&#x43C;&#x44F;</property>
                    <child>
                      <object class="GtkCellRendererText" id="cellrenderertext1"/>
                      <attributes>
                        <attribute name="xalign">0</attribute>
                        <attribute name="sensitive">0</attribute>
                        <attribute name="text">0</attribute>
                      </attributes>
                    </child>
                  </object>
                </child>
                <child>
                  <object class="GtkTreeViewColumn" id="treeviewcolumn2">
                    <property name="title">&#x418;&#x43A;&#x441;</property>
                    <child>
                      <object class="GtkCellRendererText" id="cellrenderertext2"/>
                      <attributes>
                        <attribute name="text">1</attribute>
                      </attributes>
                    </child>
                  </object>
                </child>
                <child>
                  <object class="GtkTreeViewColumn" id="treeviewcolumn3">
                    <property name="title">&#x418;&#x433;&#x440;&#x435;&#x43A;</property>
                    <child>
                      <object class="GtkCellRendererText" id="cellrenderertext3"/>
                      <attributes>
                        <attribute name="text">2</attribute>
                      </attributes>
                    </child>
                  </object>
                </child>
              </object>
            </child>
            <child type="label">
              <object class="GtkLabel" id="label1">
                <property name="visible">True</property>
                <property name="label" translatable="yes"><b>TreeView</b></property>
                <property name="use_markup">True</property>
              </object>
            </child>
          </object>

Can you explain why I get the warnings?

4

1 に答える 1

4
<attribute name="xalign">0</attribute>
<attribute name="sensitive">0</attribute>
<attribute name="text">0</attribute>

This says that you want the xalign, sensitive, and text properties of the cell renderer to be set to the value of column 0.

For example, if a row in your model looks like this:

column0=A  column1=B  column2=C

those lines in the xml will set the xalign, sensitive, and text of the first cell to A, whatever value A is, which is most likely not what you want.


In Glade, you can change these settings by right-clicking on the treeview, selecting Edit..., and then going to the Hierarchy tab. You should see three columns with one cell renderer each.

The rest depends on what you want to do. If you don't know what xalign and sensitive are, they were probably set by accident, so just change them back to -1 (this is equivalent to removing the corresponding attribute elements from the XML). text is probably correct, so leave it at 0.

If you want to learn more about cell renderer attributes, you can probably start from the tree widget overview and TreeViewColumn.add_attribute documentation. Unfortunately these do not explain the concept very clearly; you may get better explanation elsewhere.

于 2011-02-06T11:17:50.003 に答える