Unable to see image inserted onto the toolbotton

I have inserted all the widgets according to this layout that you can see below.

I create toolbar and toolbotton

	// Create a new ToolBar
	Gtk::Toolbar *newZoomToolBar = new Gtk::Toolbar();
	// Create a new ZoomIn Button
	Gtk::ToolButton *newZoomInButton = new Gtk::ToolButton();
	// Create a new ZoomOut Button
	Gtk::ToolButton *newZoomOutButton = new Gtk::ToolButton();

Insert the image into the toolbotton

	std::cout<<"Updating image"<<std::endl;
	Gtk::Image *zoomInImage = new Gtk::Image();
	zoomInImage->set_from_resource("/mnt/ws/testing/test/icons/plus.png");
	newZoomInButton->set_icon_widget(*zoomInImage);
	Gtk::Image *zoomOutImage = new Gtk::Image();
	zoomOutImage->set_from_resource("/mnt/ws/testing/test/icons/minus.png");
	newZoomOutButton->set_icon_widget(*zoomOutImage);
	std::cout<<"Inserting into toolbar"<<std::endl;
	newZoomToolBar->insert(*newZoomInButton,0);
	newZoomToolBar->insert(*newZoomOutButton,1);

Add page to the notebook
cameraNotebook->append_page(*newGrid,camString);

Add Overlay to position 2,2 inside the grid
newGrid->attach(*Gtk::manage(new Gtk::Overlay()),2,2,1,1);

Create pointer to fetch the widget

	// Here, you get a raw pointer to a widget:
    Gtk::Widget* pWidget = newGrid->get_child_at(2, 2);

    // We cast it to its most derived type:
    Gtk::Overlay* pOverlay = dynamic_cast<Gtk::Overlay*>(pWidget);

Try to add main and child widgets to the overlay

    // checking if overlay is present
    if (pOverlay)
    {
    	pOverlay->add(*newScrollWindow);
    	pOverlay->set_name(Glib::ustring::format(camOverlayName));
    	pOverlay->add_overlay(*newZoomToolBar);
    	pOverlay->reorder_overlay(*newZoomToolBar,2);
    }

After this statement pOverlay->add_overlay(*newZoomToolBar);

I get this error I can’t see images I pushed into the toolbar

  	(notebookTest:1605043): Gtk-CRITICAL **: 17:11:06.925: gtk_widget_translate_coordinates: assertion 'GTK_IS_WIDGET (src_widget)' failed

  	(notebookTest:1605043): Gtk-CRITICAL **: 17:11:06.925: gtk_widget_get_allocated_width: assertion 'GTK_IS_WIDGET (widget)' failed

  	(notebookTest:1605043): Gtk-CRITICAL **: 17:11:06.925: gtk_widget_get_allocated_height: assertion 'GTK_IS_WIDGET (widget)' failed

How can I correct it?

set_from_resource() is not adding from the filesystem, but from a Glib::Resource which can be used to combine the images, ui definitions, etc. into the executable: glibmm: Gio::Resource Class Reference . It looks like you are trying to add from the file system, so set_from_file() is the appropriate function.

Not sure what the criticals are supposed to be, also the GTKMM code looks a bit off, but my GTKMM is a bit rusty

Thanks for pointing out. According to this gtkmm documentation of Gtk::Image, there seems to be no set_from_file so I tried set it worked.

I do still get the error. Don’t seem to know why

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.