I am lookng for a way of rendering some gtk widget container to pixbuf for later use in drag'n'drop icon image using gtkmm3.
The correct way in native gtk3 to do this is, as far i researched, - usage of gtk_widget_draw() on supplied cairo surface.
The creation of this surface is not an issue, however the call to gtk_widget_draw() itself is.
Only place where it mentioned directly in gtkmm-3.4.2 sources is Gtk::Widget::draw() function (widget.cc:310), which is declared as `protected'.
So my question is: how do i properly perform such task (rendering widget to pixbuf) in gtkmm3?
At this point i see two options:
Subclass Gtk::Widget to provide public interface to protected draw() function
Extract gobj* instance from Gtk::Widget and call native Gtk's gtk_widget_draw() on this instance.
The question is: which way is preferable and why? Or maybe there are some other [better] ways to do it?
You could use a GtkOffscreenWindow
to gather a pixbuf of your widget, from the docs :
The idea is to take a widget and manually set the state of it, add it to an OffscreenWindow and then retrieve the snapshot as a Gdk::Pixbuf.
and the function:
Glib::RefPtr<Gdk::Pixbuf> Gtk::OffscreenWindow::get_pixbuf ( )
Retrieves a snapshot of the contained widget in the form of a Gdk::Pixbuf.
You can also gather some example code (in python) and extra tips, from this related question: