GNOME Bugzilla – Bug 671912
Adding image to button in GtkBuilder fails
Last modified: 2018-04-14 23:59:44 UTC
In cheese, until worked around, we would get errors like: Gtk-WARNING **: Attempting to add a widget with type GtkImage to a GtkToggleButton, but as a GtkBin subclass a GtkToggleButton can only contain one widget at a time; it already contains a widget of type GtkLabel This is caused by the order of the properties listed in the ui file. This fails: <object class="GtkToggleButton" id="burst_toggle_button"> <property name="related-action">burst_mode</property> <property name="use-action-appearance">False</property> <property name="tooltip_text" translatable="yes">Photo burst mode</property> <child> <object class="GtkImage" id="burst_toggle_button_image"> This works: <object class="GtkToggleButton" id="burst_toggle_button"> <property name="use-action-appearance">False</property> <property name="related-action">burst_mode</property> <property name="tooltip_text" translatable="yes">Photo burst mode</property> <child> <object class="GtkImage" id="burst_toggle_button_image"> Because when setting related-action, the label will already have been synced, thus the GtkBin child spot taken, meaning we cannot add our own GtkImage child. Thanks to Emmanuele for the debugging.
For the record, the workaround for Cheese was discussed in bug #671913 [1]. Bastien, what is the wanted solution for this problem? GTK+ should not care about the ordering? [1] https://bugzilla.gnome.org/show_bug.cgi?id=671913
I'm not sure I would call this a bug. FWIW Glade takes special care to ensure that we serialize the "use-action-appearance" property (if specified) before the "related-action" property, specifically for this reason.
(In reply to comment #1) > For the record, the workaround for Cheese was discussed in bug #671913 [1]. > > Bastien, what is the wanted solution for this problem? GTK+ should not care > about the ordering? That might not really be possible (not caring about ordering). If they were construct properties, it would be possible to not care about the ordering, and have the GObjectClass.constructed() vfunc take care of setting things up correctly before children are ever added. However, since these are not construct properties they take effect after the constructor runs, which means that one must be set before the other is set. But... in another light, perhaps what should be going on is that setting use-action-appearance to FALSE *after* having set "related-action", should undo the effects of having set "related-action" in the first place (that would essentially make the order of property settings more arbitrary). This is a little spaghetti right now because, setting the related action, causes the button to set label text on itself, setting the label text causes a GtkLabel to be added to the button... (but unsetting the label text of a button does not destroy the child GtkLabel to my knowledge).
We're moving to gitlab! As part of this move, we are moving bugs to NEEDINFO if they haven't seen activity in more than a year. If this issue is still important to you and still relevant with GTK+ 3.22 or master, please reopen it and we will migrate it to gitlab.
As announced a while ago, we are migrating to gitlab, and bugs that haven't seen activity in the last year or so will be not be migrated, but closed out in bugzilla. If this bug is still relevant to you, you can open a new issue describing the symptoms and how to reproduce it with gtk 3.22.x or master in gitlab: https://gitlab.gnome.org/GNOME/gtk/issues/new