How do you set an enum property on a GLib object?

后端 未结 2 479
不思量自难忘°
不思量自难忘° 2021-01-24 02:24

I am trying to set the \"ellipsize\" enum property on a GtkCellRendererText object.

I am trying to use g_object_set_property as follows:

Gtk         


        
相关标签:
2条回答
  • 2021-01-24 02:44

    Using g_object_set instead works:

    g_object_set (G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
    
    0 讨论(0)
  • 2021-01-24 02:47

    You need to initialise the GValue container with the type of the enumeration that the property expects. G_TYPE_ENUM is the generic, abstract enumeration type.

    The "ellipsize" property of GtkCellRendererText expects a PangoEllipsizeMode enumeration value, which has a GType of PANGO_TYPE_ELLIPSIZE_MODE.

    GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
    
    GValue val = G_VALUE_INIT;
    
    g_value_init (&val, PANGO_TYPE_ELLIPSIZE_MODE);
    g_value_set_enum (&val, PANGO_ELLIPSIZE_END);
    
    g_object_set_property (G_OBJECT(renderer), "ellipsize", &val);
    
    // Always unset your value to release any memory that may be associated with it
    g_value_unset (&val);
    
    0 讨论(0)
提交回复
热议问题