tags:

views:

70

answers:

1

I'm trying to create new GTK Notebook tabs that contain both a name (as a Label) and a close button (as a Button with an Image) with the following code:

Label headerLabel = new Label();
headerLabel.Text = "Header";
HBox headerBox = new HBox();
Button closeBtn = new Button();
Image closeImg = new Image(Stock.Close, IconSize.Menu);

closeBtn.Image = closeImg;
closeBtn.Relief = ReliefStyle.None;

headerBox.Add(headerLabel);
headerBox.Add(closeBtn);
headerBox.ShowAll();

MyNotebook.AppendPage(childWidget, headerBox);

This seems to work just fine; however, the button is about 1.5 - 2 times the size is needs to be, so there is a lot of extra space around the image inside the button. Having looked at remove inner border on gtk.Button I now see that the culprit is the "inner-border" style property of the GtkButton, but (being new to GTK) I can't seem to figure out how to override its value.

Is there some method of doing this that I'm missing? I don't have any reservations about not using a Button/Image combination, so any more obvious suggestions are welcome.

Note: I have seen the suggestion in the linked question to use an EventBox, but I was not able to add the Relief and mouseover effects to that Widget.

A: 

Add items to box using Gtk.Box.PackStart/PackEnd methods rather than generic Gtk.Container.Add method. PackStart/PackEnd will allow you control how child widgets will be allocated space:

headerBox.PackStart (headerLabel, true, true, 0);
headerBox.PackEnd (closeBtn, false, false, 0);
el.pescado
Thanks for the help, but using PackStart/PackEnd doesn't seem to change anything; the button takes up the same amount of space as when I used Add. From what I have read, I think the problem is related to the default inner-border size of GtkButtons.
Chumpy