Search code examples
c++gtkgtkmmgtk3

Create a Gtk Button with an image in the background, and a label in front of it


Okay, I'm trying to create a Gtk button in C++ (gtkmm 3.0) that has an image in the background that I can change depending on state, and a label in the foreground that I can change depending on a language string. I tried extending the Gtk::EventBox class which works great for the image, but I can't put a label in it. I tried extending Gtk::Container class but then I can't put it in my Gtk::VButtonBox. There has to be a better way of doing this without re-inventing the wheel.

Any suggestions would be greatly appreciated.

Thanks, Paul


Solution

  • Actually you will need to invent the wheel. What you need is composition of two widgets. I know there's a implementation of someting like that in Gedit, Nautilus, and the new Gtk+ 3.1.X includes a widget that does something like that called GtkOverlay.

    • GtkOverlay is a new container that allows to place one or more
      'overlay' widgets on top of another widget. This can be used for 'floating statusbars' and similar interfaces.

    That comes from here. You have two choices, you wait for it to come out, or you copy and the code and adapt it to your app till the new Gtk+ get released.