user-interfacegtkgtkmmgtkmm3

How to hide an image in a Gtk::Button


I've inherited a code that does this:

if (ok){
    m_Test_Button.set_image(m_Image_OK);
    m_Test_Button.set_image_position(Gtk::POS_RIGHT);
    m_Test_Button.set_always_show_image(true);
}else{
    m_Test_Button.set_image(m_Image_not_OK);
    m_Test_Button.set_image_position(Gtk::POS_RIGHT);
    m_Test_Button.set_always_show_image(true);
}

At certain points, the previous programmer who wrote that code attempted to use m_Test_Button.set_always_show_image(false); to hide the image. However, that does not really work to hide the image; it remains visible when it should stop being visible, which is a potential cause of confusion for users when changing parameters because the previous test's status prior to the change still remains visible.

I guess I can hide it just by using a blank image in its place, but there are reasons not to do it (like alignment considerations, and the fact that it looks like a kludge rather than a solution).

The Gtk::Button help does not even mention set_always_show_image() or almost anything at all related to images (other than an icon path). The only documentation I've found online seems to indicate that as the name implies, this function might not hide the image.

So I'm in the blue as for what to do to properly hide the image. I've no previous experience with Gtkmm.

Update: The underlying problem was that, partly due to my inexperience with Gtkmm, I was checking the docs for a different version of Gtkmm to the one I was using. Thanks to the commenters for making me aware of this.


Solution

  • The set_always_show_image() seems to force the button to show the image, even if, by default, Gtkmm would have hidden it (because it would look weird, for example). According to the docs:

    The image can be unset by assigning nullptr to property_image().

    As far as documentations goes, I have had the same problem with versions as you in the past. You can look at this page, which will contain the API documentation for all versions. You can also look at this answer, in which I provide a couple different ways to find information on Gtkmm I have found over the years.