I am trying to create and remove GtkCheckButton(s) to and from a GtkBox from inside a callback. The adding part works as expected but removing doesn’t quite work.
I create and add them with:
And while I have noticed that the widget object itself is removed and unreferenced, it does not disappear from the “box”, at least not until I resize the window. This will cause the callback to be called again but it will not touch the box again. Just redraw a texture inside a GtkGlArea widget.
Is there something deep I have missed regarding altering containers from inside callbacks? Should the child widget have disappeared from the GtkBox when I issue the gtk_box_remove command?
Do you try to remove a widget from a callback that is connected to that widget, e.g. connect a callback to the “clicked” signal of a button, and then remove the button itself in the callback? And is it GTK3 or GTK4?
No. The “callback” in question is a callback for GtkGLArea and the widget (the GtkCheckButton) is added from the callback to a GtkBox. I will try the show_all you suggested. Will update this thread if that works. Thanks for the suggestion anyway.
I assume you are using plain C, so it should be easy for you to convert my Nim code to C, just use the long C names like gtk_button_new(). I passed the box and the button to delete asd an tuple to the callback, in C you may use a struct or global data. Well, you said that you are using check buttons in your original code…
If it still does not work for you, please post your C test code.
Of course, we should press the button with label " Remove B2" only once! For me display updates immediately.
I have noticed that just moving the mouse pointer (no clicking) over other GtkCheckButton(s) I have in the application window will remove the check button from the Box that was supposed to be removed from the callback. The (other) checkbuttons are not related to the callback that adds and tries to remove checkbuttons.
I just saw your last post while writing. Yes, this is pretty much what I am trying to do. Obviously, “activate” is a callback but maybe GtkApplication handles something differently. I don’t know. Obviously, I am quite confused atm.
the “a->id” is just an incoming (let’s call it) object that contains the unique id of the object to be removed (or added in the case a->id is something new to be handled). “aw” refers to a widget to be added or removed.
I have tried both Wayland (my default desktop) and Xorg. Same behavior. Xorg has some weird rendering problems that eventually go away but thy are a bit annoying which is why I am back on Wayland.
There is a gtk_widget_queue_draw() in gtk4 but it has no effect.
What does have an effect is to do all that I do in my remove section inside a g_idle_add(). I don’t know why it makes a difference and it feels like the wrong solution but I have to take it until it blows up something else.