Reputation: 117
I am having some trouble displaying a PNG file in a Gtk::Window. I tried creating a Gtk::Pixbuf from the file and then create a Gtk::Image using that. Then I tried adding the Gtk::Image to the Gtk::Window but all I'm getting a blank screen. What am I doing wrong?
class CMainWindow : public Gtk::ApplicationWindow
{
public:
CMainWindow();
~CMainWindow();
};
CMainWindow::CMainWindow()
{
Glib::RefPtr<Gdk::Pixbuf> pic = Gdk::Pixbuf::create_from_file("image.png");
Gtk::Image* img = Gtk::manage(new Gtk::Image(pic));
add(*img);
}
CMainWIndow::~CMainWindow() {}
int main(int argc, char** argv)
{
app = Gtk::Application::create(argc, argv,"org.gtkmm.examples.base");
CMainWindow c;
return app->run(c);
}
Upvotes: 0
Views: 637
Reputation: 16873
While Gtk::Application::run()
will ensure that the CMainWindow
is shown, it does not try to show all of its children. In your constructor, add a call to img->show();
.
I recall seeing a blog post reporting that the next version of GTK+ (hence also the next version of gtkmm, presumably) will change the default behavior so that widgets are shown by default. But for now, one has to remember to show them.
Upvotes: 1