Hi, I’m using Gtkmm4, and I need to position some labels over a texture, as seen in the following image:
I was wondering what is the best way to do that, I’m thinking of adding a grid on top of the texture, and attaching the labels to it.
How can I add a grid on top of a Gtk::Picture class? Should I use Gtk::Overlay to hold the Grid?
Other suggestions are welcome too
A grid is not meant for absolute or relative positioning. You will probably have an easier time implementing a custom widget and laying out the positions of the text yourself.
If the labels do not need to be interactive, you can just use
Gtk::Snapshot::render_layout in the
snapshot vfunc. If they do need to be interactive, you can create some
Gtk::Labels as children and then position them in your
Thx for the quick reply, but I’m afraid I don’t understand how to use Gtk::Snapshot::render_layout.
Can you give an example or psuedo code?
The simplest I could think of would be a sample usage in the gtk4 source code, simplified you can do something like:
my_widget_snapshot (GtkWidget *widget, GtkSnapshot *snapshot)
double x, y; // TODO - set position
PangoLayout *layout = gtk_widget_create_pango_layout (widget, "my text");
gtk_widget_get_style_context (GTK_WIDGET (area)),
It should be very similar in C++. See the custom widget example for how to create a subclass with a snapshot vfunc.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.